I have added a command on StackLayout using TapGestureRecognizer but it didn't called on viewmodel class.
Here is xaml code:
<StackLayout Padding="10" Spacing="0">
<Image Source="edit_black" WidthRequest="20" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding EditServiceCommand}" CommandParameter="{Binding .}" />
</StackLayout.GestureRecognizers>
</StackLayout>
ViewModel class Command method:
public ICommand EditServiceCommand
{
get => new Command((item) => { _popupNavigation.PushAsync(new AddServicePopup("edit"), true); });
}
Please update your view model command code to the following
private ICommand _EditServiceCommand;
public ICommand EditServiceCommand => _EditServiceCommand ?? (_EditServiceCommand = new Command((item) =>
{
_popupNavigation.PushAsync(new AddServicePopup("edit"), true);
}));
you need to tell the command what type item is.
public ICommand EditServiceCommand
{
get => new Command<CommandParameterType>((item) => { _popupNavigation.PushAsync(new AddServicePopup("edit"), true); });
}
But in your code you're not using item so you can call the command without a CommandParameter.
get => new Command(() => _popupNavigation.PushAsync(new AddServicePopup("edit"), true));
Related
I created a Laravel Jetstream lifewire page from a tutorial.
I show a list of records, and added a details button.
<button wire:click="showdetails({{ $vehicle->id }})"class="inline-flex items-center px-2.5 py-1.5 border border-transparent text-xs font-medium rounded shadow-sm text-white bg-blue-500 hover:bg-blue-700">
Details
</button>
When I click onto this button, I want to see the detail page of the record (new view, not the view of the list).
Info vehicle.php I added this function
public function showdetails($id)
{
$this->vehicle = Vehicle::find($id);
return view('livewire.vehicle.details');
}
I made something wrong, because this view will not be shown.
How can I solve this problem?
Thanks for help!
Create a route to your Livewire ShowVehicle component:
Route::get('/vehicle/{id}', ShowVehicle::class);
Redirect to that route:
public function showdetails($id)
{
return redirect()->to("/vehicle/$id");
}
Display item details with ShowVehicle component:
class ShowVehicle extends Component
{
public $vehicle;
public function mount($id)
{
$this->vehicle = Vehicle::find($id);
}
public function render()
{
return view('livewire.vehicle.details', [
'vehicle' => $this->vehicle,
]);
}
}
I have site - user choose option from dropdown, depends oh his select site must to be generated. I use JS and blazor. I have 404 error. I tried to adapted this way: Populate DropDownList from another DropDownList
View:
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
#model IEnumerable<Article>
#section Scripts{
<script>
function load() {
var e = document.getElementById('titles');
var id = e.options[e.selectedIndex].value;
var Id = parseInt(id);
//C: \Users\patryk\source\repos\Blog\Controllers\Dashboard\EditPartialViewController.cs
alert(Id);
$('#container').load("/Dashboard/EditPartialViewController/_tableSeeder?id="+Id);
}
</script>
}
<h1>Edit</h1>
<form id="id_select" >
<label for="article">Choose an article to edit:</label>
<select id="titles" onchange="load()">
#foreach (var x in Model)
{
<option value=#x.Id>#x.Title</option>
}
</select>
<br><br>
There is my partialView:
#model List<Article>
#foreach (var item in Model)
{
<option value="#item.Id">
#item.Title
</option>
}
Controller for partial view:
namespace Blog.Controllers.Dashboard
{
public class EditPartialViewController : Controller
{
private ApplicationDbContext context;
public EditPartialViewController(ApplicationDbContext _context)
{
context = _context;
}
public IActionResult _tableSeeder(int id)
{
List<Article> model = context.Articles.Where(x => x.Id == id).ToList();//list with only one element
return PartialView(model);
}
}
}
WebBrowser gives me 2 errors:
GEThttps://localhost:44336/Dashboard/EditPartialViewController/_tableSeeder?id=14
[HTTP/2 404 Not Found 7ms]
and second one:
XML error - main element not found (or sth like that)
EDIT: my routing:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
endpoints.MapControllerRoute(
name: "Dashboard",
pattern: "{controller=Dashboard}/{action=Dashboard}");
endpoints.MapRazorPages();
//added for block registration
endpoints.MapGet("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
endpoints.MapPost("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
});
I have the following form component:
export class LoginPage extends React.PureComponent {
render() {
return (
<div>
<Form onSubmit={this.props.onSubmitForm}>
<Input id="username" type="text" value={this.props.username} />
<button type="submit">Submit</button>
</Form>
</div>
);
}
}
Just after the component I have a mapDispatchToProps function:
export function mapDispatchToProps(dispatch) {
return {
onSubmitForm: (evt) => {
// I need to access the `username` property here to pass it as argument.
dispatch(postUsername(username));
},
};
}
I need to access the username inside the mapDispatchToProps function.
What is the simplest way to do it? I don't need to store the username in this step.
Thank you.
You can use the event.target.username.value property, so your code should look like this:
export function mapDispatchToProps(dispatch) {
return {
onSubmitForm: (evt) => {
// I need to access the `username` property here to pass it as argument.
dispatch(postUsername(evt.target.username.value));
},
};
}
By doing this you should have the username value.
I am creating custom module (I am learning how to make custom modules), and at the moment I have problem how to get custom parameters. This is XML part, for defining custom parameter:
<config>
<fields name="params">
<fieldset name="email_settings" label="Email Setting">
<field name="email_receiver" type="text" default=""
label="Receiver Email" />
</fieldset>
</fields>
</config>
This is helper file:
class modAskUsFormHelper
{
public static function sendEmail($data)
{
$mailer = JFactory::getMailer();
}
public static function getAjax()
{
$data = modAskUsFormHelper::cleanData();
modAskUsFormHelper::sendEmail($data);
}
public static function cleanData()
{
$input = JFactory::getApplication()->input;
$data = array(
'name' => $input->get('ime', '', 'string'),
'email' => $input->get('email', '', 'string'),
'tema' => $input->get('tema', '', 'string'),
'pitanje' => $input->get('pitanje', '', 'string')
);
return $data;
}
}
When I try var_dump($this->params->get('email_receiver')); I get following error:
Fatal error: Using $this when not in object context in C:\wamp\www\joomla\modules\mod_ask_us_form\helper.php on line 21
Where is the problem?
Calling parameters in the helper.php is a little different to what you would normally use. You would achieve it like so:
public static function getParams($instance = 'mod_your_module'){ // replace mod_your_module
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule($instance);
$moduleParams = new JRegistry;
$moduleParams->loadString($module->params);
return $moduleParams;
}
Then to call then in another function, simply use the folowing:
$params = static::getParams($instance);
$displayName = $params->get('email_receiver');
Hope this helps
for component you can get config options by following the method below:
jimport('joomla.application.component.helper');
$isEnableMap = JComponentHelper::getParams('com_mycomponent')->get('enable_map');
var_dump($isEnableMap);exit;
My Telerik MVC 3 grid is filled via Ajax. After inserting a row I need to rebind my grid. When I'm doing a rebind on the OnSave() event the data rebind is still sending on the Controller Action. I need something like an OnInserted event.
Any idea?
Use the following criteria,
#(Html.Telerik().Grid<PackageDetails>()
.Name("gvPackage")
.DataKeys(keys => keys.Add(k => k.PKG_CODE))
.Columns(column =>
{
column.Bound(c => c.PKG_NAME).Title("Description").Width(200);
column.Bound(c => c.MESG_UNIT).Title("Measuring Unit").Width(100);
column.Bound(c => c.STD_QNT).Title("Quantity").Width(100);
column.Bound(c => c.MODEL).Title("Model").Width(100);
column.Bound(c => c.COMP_CODE).ClientTemplate("<input type='text' id='txtSerial<#=COMP_CODE#>' value='<#=PKG_NAME#>' />").Title("Serial Number");
column.Bound(c => c.COMP_DESC).Title("Model").Width(100);
})
.DataBinding(dbBindings => dbBindings.Ajax().Select("_PackageDetailsLoad", "SalesDept"))
)
Controller Code
[GridAction]
public ActionResult _PackageDetailsLoad(string programID, string projectID, string packageID)
{
objLoginHelper = (LoginHelper)Session["LogInInformation"];
return View(new GridModel<PackageDetails>
{
Data = salesDal.ReadPackageDetails(programID, projectID, packageID)
});
}
In JavaScript use the following Code
$('#ddlProgram').change(function () {
LoadPackageAndBindGrid();
});
function LoadPackageAndBindGrid() {
var params = {
programID: $('#ddlProgram').val(),
projectID: $('#ddlProject').val(),
packageID: $('#ddlPackage').val()
};
var grid = $('#gvPackage').data('tGrid');
grid.dataSource._data = [];
// Reload The Package Details
grid.ajaxRequest(params);
}
You can rebind your grid by returning a GridModel from your controller after performing your insert code:
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult _ItemInsert(int id, MyObject obj)
{
//Rebind the grid by sending the GridModel back
return View(new GridModel(myData)); // where myData is your grid data
}
Don't forget to decorate your controller with [GridAction].
This assumes your grid has an ajax DataBinding declaration as follows:
dataBinding.Ajax()
.Insert("_ItemInsert", "Item" })
It depends on how you're adding the row. The grid should update automatically if you're doing in-grid editing. If you're adding a record from a form, you can use the client-side rebind() method to refresh the grid data.
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html#rebind
On Complete Of Your Action you can call:
jQuery("#gvPackage").data("t-grid").ajaxRequest()