Below is the code to select all the server
<input type="checkbox" id="all_maintenace" style="vertical-align: middle;"
name="all_chkb_maintenace" value=""> Maintenace All </th>
Below is the code to select individually
<input type="checkbox" id="maintenace_{{ $value->id }}"
style="vertical-align: middle;" name="chkb_maintenace[]" value="{{ $value->id }}"
{{ ($value->websiteStatus==0)?"checked":'' }}>
<input type="text" name="chkb_all_users[]" value="{{ $value->id }}" hidden>
Below will be the code to disable / freeze the maintenance checkboxes
<input type="checkbox" id="freeze_{{ $value->id }}"
style="vertical-align: middle;" name="frz_maintenace[]" value="{{ $value->id }}">
<input type="text" name="chkb_all_users_frz[]" value="{{ $value->id }}" hidden>
Below will be the script
$(document).on('click', '#all_maintenace', function() {
var checkboxes = $('.checkbox_maintenace');
var chk_value = $('.checkbox_maintenace').val();
$.each(checkboxes, function(i, v) {
var disabled = $(v).prop("disabled");
var checked_length = $(v).is(":checked");
$(v).prop("checked", $('#all_maintenace').prop("checked"));
if (disabled && !checked_length) {
$(v).prop('checked', false); // Unchecks it
} else if (disabled && checked_length) {
$(v).prop('checked', true); // Checks it
}
});
});
$(function() {
$(".checkbox_freeze").on("change", function() {
var ticked = $(this).val();
const checked = this.checked;
$("#maintenace_" ticked).attr("disabled", checked)
});
});
controller:
$all_user = $request->chkb_all_users;
$selected_user = $request->has('chkb_maintenace') ? $request->chkb_maintenace : [];
$un_selected_user = array_diff($all_user, $selected_user);
So my question is how do I pass to the controller the checkbox value that I have disabled/frozen, while the other checkboxes that I have not disabled/frozen are passed into the controller
CodePudding user response:
you can use simple machanism to solve it. use hidden text field and when you checked your checkbox you can assign value as a '1'. when you freeze it you can assign it as a '0'. very simple
<input type="hidden" id="checkbox_status" value="0" />
js side you can change that value when you click checkbox
$('#checkbox_status').val(1);
CodePudding user response:
Very simple.Do like this
<input type="checkbox" id="freeze_{{ $value->id }}"
style="vertical-align: middle;" name="frz_maintenace[]" value="{{ $value->id }}">
<input type="text" name="chkb_all_users_frz[]" value="{{ $value->id }}" hidden>
<input type="hidden" id="checkbox_status" value="0" />
your js should like this
$(function() {
$(".checkbox_freeze").on("change", function() {
var ticked = $(this).val();
const checked = this.checked;
if(checked){
$('#checkbox_status').val(1);
} else {
$('#checkbox_status').val(0);
}
$("#maintenace_" ticked).attr("disabled", checked)
});
});