I have big complex form, there can be similar checkboxes with the same class or even name. So I need that some of them would restricted from checking more then once. I found good examples how to do that but none of them worked for me. Can someone take a look and say what I'am doing wrong thanks. When pushing green button script generates similar form so i need that checkbox pagrindines would be allowed to select once through all generated forms if there is selected no more can be in other places ofcourse would be great that deselect and changing in another checkbox work.
$('#skaicius').val(2);
$(document).ready(function(){
$('#duomenys').submit(function(){
$('#skaicius').val($('.fieldGroup').length*1+1);
})
//papildomu pareigu limitas
var maxGroup = 10;
//$('#skaicius').val(2);
//papildomu pareigu pridejimas
$(".prideti").click(function(){
if($('body').find('.fieldGroup').length < maxGroup){
var fieldHTML = '<div class="row form-group fieldGroup">'+$(".fieldGroupCopy").html()+'</div>';
$('body').find('.fieldGroup:last').after(fieldHTML);
}else{
alert('Viršintas didžiausias papildomų pareigų skaičius.');
}
});
$(document).on("change",".form-check-input",function(){
var inputklase =$(this).attr("name");
//console.log(inputklase);
$(this).closest("div").find("input."+inputklase).val($(this).is(":checked")?1:0);
})
//papildomu pareigu salinimas
$("body").on("click",".salinti",function(){
$(this).parents(".fieldGroup").remove();
});
/* not working limit
var $ckb = $(":checkbox[name=pagrindines1]").on("change", function(){
var $checked = $ckb.filter(":checked");
$ckb.not($checked).prop("disabled", $checked.length >= 1);
});
*/
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/04b00d367c.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<div class="container">
<div class="row form-group fieldGroup">
<h4>Darbuotojo pareigos</h4>
<div style="position: relative; top: 8px; left: 10px;"><a href="javascript:void(0)" class="tbtn-print btn-sm btn-success prideti" title="[Pridėti pareigas]"><span class="fas fa-plus"></span></a></div>
<div class="col-md-12">
<label class="text-black" for="kodas">Tabelio nr.</label>
<input type="text" id="tabelis" name="tabelio_numeris[]" class="form-control">
</div>
<div class="col-md-12">
<label class="text-black" for="imone">Įmonė</label>
<select class="form-control" name="imone[]" >
@foreach ($imones as $imone)
<option value=""></option>
@endforeach
</select>
</div>
<div class="col-md-12">
<label class="text-black" for="miestas">Miestas</label>
<select class="form-control" name="miestas[]" >
@foreach($miestai as $miestas)
<option value=""></option>
@endforeach
</select>
</div>
<div class="col-md-2">
<label class="text-black" for="test2">Pad. kodas</label>
<input type="text" id="test2" name="padkodas[]" class="form-control">
</div>
<div class="col-md-10">
<label class="text-black" for="padalinys">Padalinys</label>
<select class="form-control" name="padalinys[]" >
@foreach ($padaliniai as $p)
<option value=""> - </option>
@endforeach
</select>
</div>
<div class="col-md-2">
<label class="text-black" for="test2">Pareigu kodas</label>
<input type="text" id="test2" name="parkodas[]" class="form-control">
</div>
<div class="col-md-10">
<label class="text-black" for="pareigos">Pareigos</label>
<select class="form-control" name="pareigos[]" >
@foreach ($pareigos as $par)
<option value=""> - </option>
@endforeach
</select>
</div>
<div class="col-md-6">
<label class="text-black" for="dpradzia">Darbo pradžia</label>
<input type="date" id="darbo_pradzia" name="darbo_pradzia" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="bandomasis_laikotarpis">Bandomasis laikotarpis</label>
<input type="date" id="bandomasis_laikotarpis" name="bandomasis_laikotarpis" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="terminuota_sutartis">Terminuota sutartis</label>
<input type="date" id="terminuota_sutartis" name="terminuota_sutartis" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="atldata">Atleidimo data</label>
<input type="date" id="atldata" name="atleidimo_data" class="form-control">
</div>
<div class="col-md-12">
<input type="checkbox" name="vadovas1" style="margin-left: 5px; margin-top:10px;" class="form-check-input" value="1" >
<input class="vadovas1" type="hidden" name="vadovas[]" value="0">
<label class="form-check-label" style="margin-left: 25px; margin-top:5px;" id="vadovastxt">Vadovas</label>
</div>
<div class="col-md-12">
<input type="checkbox" style="margin-left: 5px; margin-top:10px;" class="form-check-input pagrindines" value="1" name="pagrindines1" >
<input class="pagrindines1" type="hidden" name="pagrindines[]" value="0">
<label class="form-check-label" style="margin-left: 25px; margin-top:5px;" id="pagrindinestxt">Pagrindinės (Generuoti barkodą pagal šią kortelę.)</label>
</div>
</div>
<!-- Papildomos pareigos -->
<div class="row form-group fieldGroupCopy" style="display: none;" >
<h4>Papildomos pareigos</h4>
<div style="position: relative; top: 8px; left: 10px;"><a href="javascript:void(0)" class="tbtn-print btn-sm btn-danger salinti" title="[Šalinti]"><span class="fas fa-minus"></span></a></div>
<div class="col-md-12">
<label class="text-black" for="kodas">Tabelio nr.</label>
<input type="text" id="tabelis" name="tabelio_numeris[]" class="form-control">
</div>
<div class="col-md-12">
<label class="text-black" for="imone">Įmonė</label>
<select class="form-control" name="imone[]" >
@foreach ($imones as $imone)
<option value=""></option>
@endforeach
</select>
</div>
<div class="col-md-12">
<label class="text-black" for="miestas">Miestas</label>
<select class="form-control" name="miestas[]" >
@foreach($miestai as $miestas)
<option value=""></option>
@endforeach
</select>
</div>
<div class="col-md-2">
<label class="text-black" for="test2">Pad. kodas</label>
<input type="text" id="test2" name="padkodas[]" class="form-control">
</div>
<div class="col-md-10">
<label class="text-black" for="padalinys">Padalinys</label>
<select class="form-control" name="padalinys[]" >
@foreach ($padaliniai as $p)
<option value=""> - </option>
@endforeach
</select>
</div>
<div class="col-md-2">
<label class="text-black" for="test2">Pareigu kodas</label>
<input type="text" id="test2" name="parkodas[]" class="form-control">
</div>
<div class="col-md-10">
<label class="text-black" for="pareigos">Pareigos</label>
<select class="form-control" name="pareigos[]" >
@foreach ($pareigos as $par)
<option value=""> - </option>
@endforeach
</select>
</div>
<div class="col-md-6">
<label class="text-black" for="dpradzia">Darbo pradžia</label>
<input type="date" id="darbo_pradzia" name="darbo_pradzia" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="bandomasis_laikotarpis">Bandomasis laikotarpis</label>
<input type="date" id="bandomasis_laikotarpis" name="bandomasis_laikotarpis" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="terminuota_sutartis">Terminuota sutartis</label>
<input type="date" id="terminuota_sutartis" name="terminuota_sutartis" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="atldata">Atleidimo data</label>
<input type="date" id="atldata" name="atleidimo_data" class="form-control">
</div>
<div class="col-md-12">
<input type="checkbox" name="vadovas1" style="margin-left: 5px; margin-top:10px;" class="form-check-input" value="1" >
<input class="vadovas1" type="hidden" name="vadovas[]" value="0">
<label class="form-check-label" style="margin-left: 25px; margin-top:5px;" id="vadovastxt">Vadovas</label>
</div>
<div class="col-md-12">
<input type="checkbox" style="margin-left: 5px; margin-top:10px;" class="form-check-input pagrindines" name="pagrindines1" >
<input class="pagrindines1" type="hidden" name="pagrindines[]" value="0">
<label class="form-check-label" style="margin-left: 25px; margin-top:5px;" id="pagrindinestxt">Pagrindinės (Generuoti barkodą pagal šią kortelę.)</label>
</div>
</div>
<!-- Papildomos pareigos pabaiga -->
</div>
Aucun commentaire:
Enregistrer un commentaire