Error show data when event click livewire - laravel

I have an error when showing the data I do not see the problem because the data does not want to show it I hope you can help me.
this my event click on table its work display my modal
<td>
<a href="#" wire:click.prevent="edit({{$pais->id}})" data-toggle="modal" data-target="#update_pais">
<i class="fa fa-search text-warning"></i>
</a>
</td>
This is my component function edit
public $testNew;
public function edit(Pais $pais)
{
$this->testNew = '324234234234';
}
this my input
<input wire:model="testNew" type="text">
when click data doesn't show and input is empty on network show data is correct

Have you tried adding a value attribute to your input?
<input wire:model="testNew" type="text" value="{{ $testNew }}">

Related

Thymeleaf iteration stuck at 0 in dynamically created form (Spring Boot)

I'm trying to create a table from a list phases where each row has forms that will relate to the list item phase for that row - so row 1 has a cell for "Phase 1" and then a button that will rename "Phase 1", then the next row has "Phase 2" and a button for that.
However, when I try to access the index of that list iteration from within the form it always returns 0, so the first cell of row 2 still says "Phase 2" but the form still passes the index of "Phase 1" to the HTTP request. It can definitely still see the list, because if I change it to return phaseStat.size rather than the phaseStat.indexit gives the correct number.
The cells containing the phase name work fine, it's only once I get inside the <form> tag that it gets stuck on the first item of the list. How do I get the form to keep pace with the iteration with the rest of the table?
<table class="table">
<tr th:each="phase : ${phases}">
<td class="table-light" th:text="${phase}"></td>
<td>
<form th:action="#{/tasks/phases/rename}">
<button type="button" class="btn btn-outline-primary btn-sm" title="Rename" onclick="openForm('renamephaseform')">Rename</button>
<div class="form-popup card mb-3" id="renamephaseform">
<h3 class="card-header">Rename
<button type="button" class="btn btn-outline-secondary btn-sm closebutton" title="Close menu" onclick="closeForm('renamephaseform')">⛌</button>
<br>
</h3>
<div class="card-body">
<input type="text" class="form-control" id="phasename" placeholder="Phase name" th:name="newname">
<button type="submit" class="btn btn-primary" title="Rename" th:name="phasenumber" th:value="${phaseStat.index}">Rename <span th:text="${phase}"></span></button>
</div>
</div>
</form>
</td>
</tr>
</table>
<script>
function openForm(name) {
document.getElementById(name).style.display = "block";
}
function closeForm(name) {
document.getElementById(name).style.display = "none";
}
</script>
Edit:
The weird thing is, the iteration works perfectly fine in this example and I can't see what the difference is...
<table class="table">
<tr th:each="album : ${albums}">
<td class="table-light" th:text="${album.name} + ' (' + ${album.artist} + ')'"></td>
<td>
<form th:action="#{/index}">
<button type="submit" class="btn btn-primary btn-sm" th:name="id" th:value="${album.id}">Open album</button>
</form>
</td>
</tr></table>
So, what I ended up doing that made this work (thanks to andrewJames) is including the iteration index in the form id to create a unique name.
So for the Open button I included
th:attr="onclick='openForm(\'renamephaseform' + ${phaseStat.index} + '\')'", in the Closebutton th:attr="onclick='closeForm(\'renamephaseform' + ${phaseStat.index} + '\')'" and in the form tag th:attr="id='renamephaseform' + ${phaseStat.index}".
Elswhere, I've sometimes used string values for this (eg the phase name, task name etc) to make it easier to review in the Inspector.

Checkbox value in controller in laravel

I am trying to get all the payments that is been selected through the checkboxes and then update the value in the database by '1' which means its paid. But when I try to get the values of checkbox array I only get 1 data in the array and not all selected. Any help?
View
#foreach($sellerID as $p)
<form action="/paid/{{$p->id}}" method="post" enctype="multipart/form-data">
#csrf
<td><input type="checkbox" name="checked[]" value="{{ $p->id }}"></td>
<td> {{$p->order_number}} </td>
<td>
<input id="commission" type="text" class="form-control" name="commission"
value="{{ $p->commission_value }}" readonly autocomplete="notes" style="width: 15%;" autofocus>
</td>
<td> {{$p->product_name}} </td>
<td>
#if($p->sellet_commission_paid == '0')
<button type="submit" class="btn btn-default" style="background-color:red">
<b><em>UNPAID</b></em>
</button>
#else
<b><em>PAID</b></em>
#endif
<td>
</form>
#endforeach
Controller
$checked = $request->input('checked');
// $checkboxes = $request->checked;
dd($checked);
die();
// dd(checkboxes);
you can put almost anything you like inside a form, but not inside a table. table has a more restricted structure which you must follow.
instead of wrapping table rows with forms, you can wrap the whole table with 1 form and submit all of it and just extract the details you need,
You need to put all input element inside form :
<form action="/route">
<input ...../>
<div>
<input ...../>
</div>
</form>
A form-associated element is, by default, associated with its ancestor form element, but may have a form attribute specified to override this.
If a form-associated element has a form attribute specified, then that attribute's value must be the ID of a form element in the element's owner Document.
Try using a foreach loop.
foreach($request->input('checked') as $check){
[sample variable] = $check;
}
The array will now be stored as $check and you should be able to get each value from the input

spring boot passing parameter from list to controller

I have a list of objects in my view:
<tbody>
<tr th:each="object : ${myObjects}">
<td><span th:text="${object.id}"> </span></td>
<td><span th:text="${object.name}"> </span></td>
<td><span th:text="${object.address}"></span></td>
<td>
<a href="#" data-toggle="modal" data-target="#ADD_SOME_INFO_MODAL">
<i class="fas fa-plus"></i>
</a>
</td>
</tr>
</tbody>
button in last column starts a modal. In modal I can add some value for a record:
<form th:action="#{/add-data}"
method="post"
class="form">
<input name="NEW-DATA">
<div class="modal-footer">
<button name="login-submit"
type="submit">
<i class="fas fa-plus"></i>
</button>
</div>
</form>
and this is my controller:
#PostMapping("/add-data")
public String addData(#RequestParam String URL) {
... do logic...
return "index";
}
I get correct input value in my addData() method, but I cannot find a way to pass an id from object that was clicked on a list in a first place.
I need this object id to be able to correctly store additional information.
I think of maybe doing separate page for adding this information for each record but that seems not right with easy and small eddits/additions.
Is there any way to be able to add edits on modals in Spring Boot? I was not able to find proper answer for that anywhere, so here I am.
You are passing the URL param to the Controller, simply pass the value to the controller in the same way.
The glue you need is in JavaScript. When the user clicks the button to open the modal, use JS to copy the value to a hidden input field on the modal Form tag. When the form is submitted, then your copied value will also be submitted and available in your controller. You can write the hidden input field with a dummy value and then change the value via JS.
<input type="hidden" id="myHiddenField" name="myHiddenField" value="CHANGE_ME">
Your button to open the modal can look like this:
<i class="fas fa-plus" onclick="document.getElementById('myHiddenField').value='${object.id}'"></i>
Now hidden field in modal form has the value you want.

How to use multidimensional checkbox v-model in vuejs

Suppose i have some subjects which has conditions and groups.
How can i load those first time and checked in update mood in vuejs?
<div v-for="(sub, Index) in subjects">
<b>{{ sub }} </b>
<label v-for="(subconlist) in sub['subCon']">
<input type="checkbox"
:value="subconlist.id"
:key="subconlist.id"
>
<span>{{subconlist.name}} </span>
</label>
<label v-for="clsgrlist in sublist['acGr']">
<input type="checkbox">
<span>{{clsgrlist.academic_group_name}} </span>
</label>
</div>
<button #click="saveOrUpdate()" >Save </button>
</div>
fiddle here
the table where i will save it : sub_id,condition_ids,group_ids
I have to save data based on checked value in the table with comma separated.
How can i get checkbox checked if it already found in the table, i mean when update?
I need to get subjectconditon or group ids basis on each subject when click on save button.

Laravel Request facade isn't detecting multiple submit buttons

I have two submit buttons within a form, and I need to detect which one is used to trigger a certain action. Unfortunately, my check isn't detecting which submit button was clicked:
Form:
<button type="submit" name="complete">
<span class="btn-label">
<i class="glyphicon glyphicon-save"></i>
</span> Submit Audit
</button>
<button type="submit" name="pending">
<span class="btn-label">
<i class="glyphicon glyphicon-save"></i>
</span> Save Audit
</button>
Controller:
public function updateAudit(Request $request, $id)
{
....
if ($request->has('complete')) {
$auditCompleteCheck->completed = 1;
$auditCompleteCheck->save();
}
}
If I output $request, I can see the complete submit button as: "complete" => "", and similarly with pending: "pending" => "".
But, if I dd($request->has('complete'));, it always returns false, even though I can see it in the request bag.
Why isn't the ->has check working?
Many thanks.
Try setting the same value for the attribute name for both button elements and a different value for the attribute value.
HTML part:
<button type="submit" name="submit_audit" value="complete">
<span class="btn-label">
<i class="glyphicon glyphicon-save"></i>
</span> Submit Audit
</button>
<button type="submit" name="submit_audit" value="pending">
<span class="btn-label">
<i class="glyphicon glyphicon-save"></i>
</span> Save Audit
</button>
Now in your controller, you can do the following:
if ($request->submit_audit === 'complete') {
// Do something
}
if ($request->submit_audit === 'pending') {
// Do something else
}

Resources