Wrong checked checkbox Angularjs - php

I have a problem with a template with AngularJS.
The page shows a books list with a checkbox. This is used for batch actions, like delete the books. If the list is too long, the books will be shown in a paged list
The problem is, if I check some of them and change the page number, the checkbox will be checked in the same position.
Is easier to understan with this screenshots
I check the first and the third result:
https://i.stack.imgur.com/NK5jE.jpg
Click on the next page:
https://i.stack.imgur.com/GEuMc.jpg
Distinct pages and results, same checked checkbox
The get this results I´m using a query in a action.class.php and sending the json like this:
$ejemplares = array();
foreach($data as $ejemplar_bd)
{
$id_documento = $ejemplar_bd['id_registro'];
$ejemplar = array();
$ejemplar['id'] = $ejemplar_bd['id'];
$ejemplar['idDoc'] = (int)$ejemplar_bd['id_registro'];
$ejemplar['numregistro'] = (int)$ejemplar_bd['numregistro'];
$ejemplar['codigo'] = $ejemplar_bd['codigoejemplar'];
$ejemplar['estado'] = $ejemplar_bd['estado'];
$ejemplar['signatura'] = $ejemplar_bd['signatura1']."-".$ejemplar_bd['signatura2']."-".$ejemplar_bd['signatura3'];
$ejemplar['tipo'] =$ejemplar_bd['tipoejemplar'];
$ejemplar['reservas']=$ejemplar_bd['reservas'];
$ejemplar['Ubicacion']=$ubicaciones[$ejemplar_bd['id']];
$ejemplar['Motivo']=$ejemplar_bd['motivo_expurgado'];
$ejemplar['Editorial']=$data_editorial['valor'];
$ejemplar['Imprimido']= $ejemplar_bd['imprimido'];
$ejemplar = array_merge($ejemplar,$fondos[$id_documento][$ejemplar['id']]);
$ejemplares[] = $ejemplar;
}
$this->json_data = json_encode($ejemplares);
After that, the code in the template is:
<tr ng-repeat="item in data| filter:Buscar | filtroNumregistro:numregistro | filtroCodEjemplar:codEjemplar | filtroNombreNormalizado:nombreFiltro | orderBy:sort:reverse | limitTo: (currentPage - 1) * pageSize - filtrados.length | limitTo: pageSize track by $index">
<td class="sf_admin_text sf_admin_list_td_nombre">
<input type="checkbox" name="ids[]" value="{{ item.id }}" class="sf_admin_batch_checkbox">
</td>
<td class="sf_admin_text">
{{ item.codigo }}
</td>
<td class="sf_admin_text">
{{ item.numregistro }}
</td>
<td class="sf_admin_text sf_admin_list_td_titulo">
<span><a ng-href="{{cambiarUrlTitulo(item.id)}}">{{ item.Titulo }}</a></span><br/>
<span class="autorListEjemplar" ng-repeat="autor in item.Autor">{{autor}}{{$last ? '' : ' - '}}</span>
</td>
<td class="sf_admin_text" style="width:10%;">
{{ item.ISBN }}
</td>
<td class="sf_admin_text" style="width:10%;">
{{ item.Editorial }}
</td>
<td class="sf_admin_text" style="width:10%;">
{{ item.Ubicacion }}
</td>
<td class="sf_admin_text" style="width:10%;">
{{ item.signatura }}
</td>
<td class="sf_admin_text">
{{ item.tipo }}
</td>
</tr> etc...
What is going on?
What could be the problem?
Thanks in advance

I have to replace:
<input type="checkbox" name="ids[]" value="{{ item.id }}" class="sf_admin_batch_checkbox">
for
<input type="checkbox" ng-model="item.checked" class="sf_admin_batch_checkbox">

Related

For each problems Laravel Blade

Hi I'd like to ask if my query is correct.
#foreach ($indemnity_benefits->where(['indemnity_benefit_type' => 'Ee', 'indemnity_benefit_group' => 'Basic Benefits'])->get() as $key => $benefit)
<tr>
<td>
<input type="hidden" name="bBenefitEeDesc[]" value="{{$benefit->indemnity_benefit_desc}}">
<span class="p-2">{{$benefit->indemnity_benefit_desc}}</span>
</td>
<td><input style="width: 75px;" name="bBenefitEeMaxDays[]" value="{{old('bBenefitEeMaxDays.'.$key, $benefit->indemnity_benefit_maxdays)}}" class="form-control form-control-sm"></td>
{{-- #for ($index = 0; $index < $noOfCols; $index++)
<td><input name="bBenefitEeValue{{$key}}[]" value="{{old('bBenefitEeValue'.$key.'.'.$index, '')}}" type="text" class="form-control form-control-sm"></td>
#endfor --}}
#foreach ($indemnity_values->where('indemnity_benefit_id', $benefit->id)->get() as $item)
<td><input name="" value="{{$item->indemnity_benefit_value}}" type="text" class="form-control form-control-sm"></td>
#endforeach
</tr>
#endforeach
When I put $benefit->id in the second for each only one row with columns appear. Something like this.
Here are the queries:
$sob_indemnity = SobGhIndemnityComprehensive::where('rfq_version_id', $rfq_version_id)->where('type', 'Indemnity')->first();
//Indemnity Levels
$sob_indemnity_levels = SobghIndemnityLevel::where('sob_gh_ind_comp_id', $sob_indemnity->id);
$indemnity_benefits = SobghIndemnityBenefit::where('sob_gh_ind_comp_id', $sob_indemnity->id);
$indemnity_values = SobghIndemnityBenefitsValue::where('sob_gh_ind_comp_id', $sob_indemnity->id);
Your $indemnity_values is a mutable object, so on your first line you are calling:
$indemnity_values
->where('indemnity_benefit_id', 1)
->get()
And on your second line you are calling the following that is obviously returning an empty collection.
$indemnity_values
->where('indemnity_benefit_id', 1)
->where('indemnity_benefit_id', 2)
->get()
you need to clone your query:
#foreach ((clone $indemnity_values)->where('indemnity_benefit_id', $benefit->id)->get() as $item)

Laravel/HTML - Getting the assigned ID for every <input type = "hidden"> in each table row

I am trying to pass every ID retrieved from the database by getting them from every field with a type of hidden for every table row. This is the picture of what I am currently doing:
I already assigned IDs on their respective fields but every time submit the form it always retrieves the last ID which is ID 10. For example if I clicked the one of the radio button of second row which has to be an ID of 7 it will ALWAYS retrieve the last row's ID (10) instead of its corresponding ID which is 7.
#foreach($flights_depart as $flight)
<tr>
<td>{{ $flight->flight_no }}</td>
<td>{{ $flight->departure_schedule }}</td>
<td>{{ $depart_source_country }}</td>
<td>{{ $flight->arrival_schedule }}</td>
<td>{{ $destination->country_name }}</td>
#for($y=$counter1; $y<#count($first_durations); $y++)
#php
$search = "0 Day";
$position = strpos($first_durations[$y], $search);
if($position === 0){
$currentDuration = substr($first_durations[$y], 9);
}else{
$currentDuration = $first_durations[$y];
}
#endphp
#break;
#endfor
<td> {{ $currentDuration }} </td>
<td> <!-- ECONOMY CLASS -->
#php
$total_fare1 = intval($book_details['seat_qty'] * ($booking_types[0] + $destination->country_price));
echo "<center>PHP ". number_format($total_fare1, 2, '.', ',');
echo "<br>";
#endphp
<input type="radio" name="total_departure_fare" value="{{$total_fare1}}" required>
</td>
<td> <!-- BUSINESS CLASS -->
#php
$total_fare2 = intval($book_details['seat_qty'] * ($booking_types[1] + $destination->country_price));
echo "<center>PHP ". number_format($total_fare2, 2, '.', ',');
echo "<br>";
#endphp
<input type="radio" name="total_departure_fare" value="{{$total_fare2}}" required>
</td>
<td> <!-- FIRST CLASS -->
#php
$total_fare3 = intval($book_details['seat_qty'] * ($booking_types[2] + $destination->country_price));
echo "<center>PHP ". number_format($total_fare3, 2, '.', ',');
echo "<br>";
#endphp
<input type="radio" name="total_departure_fare" value="{{$total_fare3}}" required>
</td>
<input type="hidden" value="{{$flight->flight_id}}" name="departure_flight_id"> //THIS IS FIELD THAT IS RESPONSIBLE FOR ASSIGNING IDS
</tr>
#php
$counter1++;
#endphp
#endforeach
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-10">
<button type="submit" class="btn btn-primary">
{{ __('Continue') }}
</button>
</div>
</div>
I already tried placing it outside the table row but it does not change anything. How do I retrieve the right ID for each table row?

Laravel Inserting Data Only the Last List or Data

I want to insert the data specifically look at my page.
When I set time the data will be inserted. But what I have right now is the data that is inserted is the very last data on this table which is January-31-2019 how can I fix it so when I insert data, the data will insert any of the data that is list on the table.
Controller
public function insertSchedule(Request $request)
{
$employeeTimeSet = new Schedule;
$employeeTimeSet->employee_no = $request->input('hidEmployeeno');
$employeeTimeSet->last_name = $request->input('hidEmployeeLast');
$employeeTimeSet->first_name = $request->input('hidEmployeeFirst');
$employeeTimeSet->date_today = $request->input('dateToday');
$employeeTimeSet->time_in = $request->input('timeIn');
$employeeTimeSet->time_out = $request->input('timeOut');
$employeeTimeSet->save();
$notification = array(
'message' => 'Click PLAN TIME! Employee Time Set!',
'alert-type' => 'success'
);
return redirect()->back()->with($notification, 'Employee Time Set');
}
View
{!! Form::open(['action' => 'Admin\EmployeeFilemController#insertSchedule', 'method' => 'POST']) !!}
<div class="row">
<div class="form-group col-md-12">
<small>Employee No. and Name:</small>
<b><i> {{ $employee->employee_no }} : {{ $employee->last_name }}, {{ $employee->first_name }}</i></b>
<input type="hidden" name="hidEmployeeno" value='<?php echo $employee->employee_no ?>'>
<input type="hidden" name="hidEmployeeLast" value='<?php echo $employee->last_name ?>'>
<input type="hidden" name="hidEmployeeFirst" value='<?php echo $employee->first_name ?>'>
<hr>
</div>
</div>
#php
$today = today();
$dates = [];
for($i=1; $i < $today->daysInMonth + 1; ++$i) {
$dates[] = \Carbon\Carbon::createFromDate($today->year, $today->month, $i)->format('F-d-Y');
}
#endphp
<table class="table">
<thead>
<tr>
<th>DATE TODAY</th>
<th>TIME IN</th>
<th>TIME OUT</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
#foreach($dates as $date)
<tr>
<td><b>{{ $date }}</b></td>
<input type="hidden" name="dateToday" value="{{ $date }}">
<td><input type="time" name="timeIn" class="form-control col-md-10"></td>
<td><input type="time" name="timeOut" class="form-control col-md-10"></td>
<td> {{Form::button('<i class="fa fa-clock"> SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm', 'style'=>"display: inline-block;"])}}</td>
</tr>
#endforeach
</tbody>
</table>
{!! Form::close() !!}
The issue is that you are using one form with multiple inputs in it and there is no unique name to them. If you inspect the code, your form will have 31 inputs with name timeIn and 31 inputs with name timeOut.
When you submit the form, It picks the last timeIn and timeOut.
Two soluctions
Make multiple forms (put form tags in while loop, it will create 31 forms in the page)
Use ajax to send data to the server.
You need to use [] for your textbox names. Example : name[] and you need to use a loop to post it. Example - how to get post from same name textboxes in php
In Addition to the #Swaroop's Answer there is another option. You can make array of these fields in the same form and submit them. and at the server end, you will have to loop through posted array so that you can process them further.

how to make radio buttons behave in a mutually exclusive way

I was to trying to update my checkbox value based on checked..But the problem I'm facing is i can't uncheck the old checkbox checked ..So when i click on the new checkbox the old one should be uncheck...I have used laravel platform where table header comes from database and from database the old checkbox value came..
here is my blade view :
<table class="table">
<thead>
<tr>
<th>SL No</th>
<th>Name</th>
#foreach($roles as $row)
<th>{{$row->label}}</th>
#endforeach
</tr>
</thead>
<tbody>
<?php $i=1; ?>
#foreach($users as $user)
#foreach($user->roles as $row)
<tr>
<td>{{$i}}</td>
<td>{{$user->name}}</td>
#foreach($roles as $role)
<td>
#if($role->role == $row->role)
<input type="checkbox" class="myCheckbox" checked="" >
#else
<input type="checkbox" class="myCheckbox">
#endif
</td>
#endforeach
</tr>
<?php $i++; ?>
#endforeach
#endforeach
</tbody>
</table>
Here is the javascript i used for check only one checkbox .
$('.myCheckbox').click(function() {
$(this).siblings('input:checkbox').prop('checked', false);
});
anybody could help me to find out the solution please?
Either use radio buttons, or iterate over all checkboxes setting the checked value to false and only checking the just clicked checkbox.
Here is an example.
var container = document.querySelector('.container');
container.addEventListener('click', function(evt) {
[].slice.call(this.children).forEach(function(input) {
input.checked = false;
})
evt.target.checked = true;
})
<div class="container">
<input type="checkbox"> Foo
<input type="checkbox"> Bar
<input type="checkbox"> Baz
</div>

Output Laravel collection in groups of two

I'm struggling to split the table into two columns in Laravel blade. For example if I have 17 rows, I want to display 9 of them in first column, and the rest in the second. This is my code:
#foreach($idAndProducts as $id)
<tr>
<td width="15px">
<input type="checkbox" id="products{{$id->product_id}}" name="products[]" value="{{$id->product_id}}">
<input type="hidden" name="campaignID[]" value="{{$id->id}}"></td>
<td width="480px"><label for="products{{$id->product_id}}">{{$id->products}}</label></td>
</tr>
#endforeach
Is there a way to do this within a Blade or using jQuery?
You can use array_chunk to split them into groups of two. Try this:
#foreach ( array_chunk($idAndProducts, 2) as $row )
<tr>
#foreach ( $row as $id )
<td width="15px">
<input type="checkbox" id="products{{$id->product_id}}" name="products[]" value="{{$id->product_id}}">
<input type="hidden" name="campaignID[]" value="{{$id->id}}">
</td>
<td width="480px">
<label for="products{{$id->product_id}}">{{$id->products}}</label>
</td>
#endforeach
</tr>
#endforeach
Please note that if $idAndProducts is a collection then array_chunk will not work. You will need to use the inbuilt method chunk instead. Just update the first line to read
#foreach ( $idAndProducts->chunk(2) as $row )

Categories