Hi, I have set some required fields which are hidden based on some choices. initially everything worked automatically but then suddenly when I go to add a record, it started asking me for the required but hidden and empty fields. I set the required field by code but it doesn't work.
Hide fields with "required" attribute (v2023)
-
- User
- Posts: 8
$(document).ready(function() {
function toggleIdLargeAreaUnocHabitat() {
$("#r_id_large_area_unoc_habitat").attr("required", "required");;
if ($("#x_id_area_suf_long_tern").val() == "1" || $("#x_id_area_suf_long_tern").val() == "3") {
$("#r_id_large_area_unoc_habitat").hide();
//$("#x_id_large_area_unoc_habitat").prop("required", false);
$("#x_id_large_area_unoc_habitat").removeAttr("required");
$("#x_id_large_area_unoc_habitat").val("").trigger('change');
} else {
$("#r_id_large_area_unoc_habitat").show();
//$("#x_id_large_area_unoc_habitat").prop("required", true);
$("#x_id_large_area_unoc_habitat").attr("required", "required");
}
}
toggleIdLargeAreaUnocHabitat();
$("#x_id_area_suf_long_tern").change(function() {
toggleIdLargeAreaUnocHabitat();
});
});
-
- User
- Posts: 9719
You JavaScript code should check if the field is hidden before adding the "required" attribute, see :hidden Selector.