I want to make condition if database have data js will give attr required but if database not have a single data, attr required wil removed
this for my json
$(document).ready(function () {
// ================== CHANGE ====================
$("#no_reg").change(function(e) {
console.log(e);
var no_reg_id = e.target.value;
$.get("/PickStandart/" + no_reg_id, function(data) {
console.log(data);
$('#standart').empty();
$('#standart').append('<option value="">-- Select One --</option>');
$.each(data, function (index, row) {
if (row.name != null) {
$('#standart').attr('required', 'required');
}
else {
$('#standart').removeAttr("required");
}
$('#standart').append('<option value="'+ row.id +'">' + row.name + '</option>')
});
});
});
});
my problem is, I cant remove required attr if data is null
this for my json code
$bagian = Bagian::where('id', '=', $standart)->first();
if ($bagian->standart_klausul == 1) {
$standart = Standart::where('aktif', '=', 1)->get();
return response()->json($standart);
}