How to bind variable value declared in an Angular component as a (click) function name? - angular2-databinding

onClick function name want it to pass from backend

Provided that there is a public function on the Controller named myFunction(), this should work:
<button type="submit" (click)="myFunction()"> </button>

Related

livewire alpine flatpickr getting null

I can't get this to give me the dd() of the date. It keeps coming back as null. i've implemented flatpickr correctly and all works accept when i try to get the actual date. However, when i add an additional button to submit the date with wire directive it works. But i want it to fire when a date is clicked. Any help would be appreciated. Thanks
in my livewire file.
public $date;
public function secondStepSubmit()
{ dd('date');
};
in my view
<input x-data x-init="flatpickr($refs.input, null);" wire:change="secondStepSubmit" x-ref="input" type="text" />
</div>
flatpickr has its own change event listener.
you can use that to get the value of the date of the input as follows.
<div>
<input x-data x-init="flatpickr($refs.input, {
onChange: function(dateObj, dateStr) {
#this.call('secondStepSubmit', dateStr)
}
});" x-ref="input" type="text" />
</div>
I have used #this blade directive from livewire, we also can use $wire from alpine too.
in the Livewire component,
public function secondStepSubmit($date)
{
dd($date);
}

Laravel 5.1, update multiple values from checked checkbox

In Laravel 5.1, I need to update multiple values from checked checkbox.
I can edit some registries from a table by clicking the edit button for each registry, and that button send me to the edit view
(This is de edit view for a single registry)
With the url: http://myapp/someroute/2246/edit where 2246 is some id.
Inside that edit I can update 4 fields. One of those fields is called "my state" and can have the values 1, 2 or 3.
Now, I have to make a multi select edit feature, where I can check every row of the table that I need to update simultaneously (each have the name=someid) and then click some button called "Validate", and update for evey row only 1 field, the my state field, and the new value will be always 1 (in the picture the values are string but thats only for the view).
The question is: how can I call the method update for every id that I'm selecting in the view? every input checkbox has it's own name which is the id of the registry that I will update.
The update method just validate some values from the view and then call some myeditmethod, but in this case I will jump the update and go directly to myedit which is someting like:
public function myedit(Request $request, $id) {
$obj = Self::findOrFail($id);
$obj->fk_id_comuna = $req['fk_id_comuna'];
$obj->fk_id_user = $usuario_id;
$obj->date = \Carbon\Carbon::now();
$obj->fk_id_my_state = $estado; //THIS IS THE ONLY FIELD THAT I WILL EDIT, ALWAYS WITH THE SAME VALUE `1`
$obj->save();
I was trying the make a form for that Validate button but I don't know how to handle multiple id in one call on the edit method.
<form action="{!! route('myroute.update', ['id' => [HERE, HOW CAN I PASS MULTIPLE ID FROM THE CHECKED CHECKBOX] ]) !!}" method="POST">
<input type="submit" class="btn btn-primary pull-right" value="Validar" />
</form>
I was thinking on a javascript function which collect in a array every checked checkbox name and call the myedit method directly, without the formof the view, could be?
About passing multiple values as one Request value.
Assume you have form like this:
<form method="post">
<input type="checkbox" name="options[]" value="foo"/>foo<br/>
<input type="checkbox" name="options[]" value="bar"/>bar<br/>
<input type="checkbox" name="options[]" value="buz"/>buz<br/>
<input type="submit" value="Submit" />
</form>
Your request('options') would be an array: ["foo", "bar", "buz"].
Than you can iterate over options using foreach.
Inside your update method you can go with:
foreach ($option as request('options')) {
//put your previous code here, so it'd be applied for every option
}
In JS I did this:
var optionsChecked = [];
$('.options:checkbox:checked').each( function(){
optionsChecked .push($(this).val());
});
Then in ajax:
$.ajax({
type: 'POST',
data: {'id': optionsChecked },
etc
Then in PHP:
$all = $request->input('id');
foreach ($all as $id){
//whole obj->* = *;
$obj->save();
}

How to resolve issue from laravel 5

I am receiving this error when I try to get the value from database to edit bus type form text box.
Property [name] does not exist on this collection instance. (View: E:\fyp\resources\views\buses\editbustype.blade.php)
Here is the code for edit section of controller:
public function edit(addbustype $id)
{
$bustype = addbustype::find($id);
return view('buses.editbustype', compact('bustype','id'));
}
When I changed $id to any number (1) it gives me the perfect result for that id, but only for a single one. The code for edit bus type section is here:
<div class="form-group col-md-6">
<label for="name">Company Name</label>
<input type="text" class="form-control" name="name" placeholder="Company Name" value="{{$bustype->name}}">
</div>
Note That You Are Using Route Model Binding
Than You Are Trying To Get The addbustype With $id Watch is $id Now Become An Instance Of addbustype Model So It Well Give You An Error Because
$bustype Well Now Become A Collection Of addbustype Model
So You Have To Decide Eather Use Route Model Binding Or Simply Find Function
In Your Web.php Route
The Parameter Name Must Matches With Parameter Both On Route And Edit Function
Route::get('addbustype/{addbustype}','yourCountroller#edit')
public function edit(addbustype $addbustype)
{
return view('buses.editbustype', compact('bustype'));
}
Or Simply Use Find Method
public function edit($id)
{
$bustype = addbustype::find($id);
return view('buses.editbustype', compact('bustype','id'));
}
You Can Revel To Route Model Binding For More

MVC3: Geting values of cloned objects

I have a drop down list with options from a model; and I want to add a similar drop down list when the user clicks on a button. My drop down list and button are defined as
<div id="parent">
<div class="id">
#Html.DropDownListFor(m =>m.mymodel)
</div>
</div>
<input type="button" value="submit" onclick="JSFunc()"/>
And the function, JSFunc() is
var control = document.getElementById('id').cloneNode( true );
document.getElementById( 'parent' ).appendChild( new );
How can I get the value of the clone objects from the controller?
You must set the name attribute of a newly-created <select> to something unique that matches a parameter name in your controller.
(or parameter property name, or anything else depending on the model binder and your situation)

ASP MVC 3 is it possible to identify the <input> id in the controller [post] method?

I'm using a so as to edit an object, with an <input type="submit"> for validation
I've also another input, type="button" with an onclick event for the cancel button (with a redirect). However, this use a JS call, which I'd like to avoid.
I'd rather prefer to process the validation or cancel choice within the controller, so as to be NoScript compliant.
So is it possible to retrieve, within the controller post method, the id of the <input> that was clicked in the <form>?
Thanks
You can set the name of your
<input type="submit" name="submitButton" />
Then in your controller:
if(Request["submitButton"] != null) {
// ...
}
I'm not sure if I understand you, but if your cancel button does a redirect, it should end in a GET, and your submit button does a POST, that's how you should difference both request.
Check the [HttpPost] attribute in controller action methods.

Resources