I have one form and couple of divs with bunch of input fields, and one select field that shows one div and hide all others. In those input field I have html5 required tag. I would like to remove required tag from all input fields that are in hidden divs. How can I do that? Here is my js for show/hiding divs depending on my select options:
<script>
function changeGroup(e) {
/*
1 - Remove all group classes
2 - Add the currently selected group class
*/
$("#main")
.removeClass(allGroups)
.addClass($("option:selected", e.target).val())
}
/*
1 - Bind changeGroup function to "change" event
2 - Fetch all group from the select field
*/
var allGroups = $("select")
.change(changeGroup)
.find("option")
.map(function() {
return $(this).val();
})
.get()
.join(' ');
</script>
Thank you for help... Dorijan
Click Customize the System. Under Components, expand Entities, and then expand the entity you want. Click Fields. Change the Field Requirement from Business Required to Optional.
<input type="hidden"> <input> elements of type hidden let web developers include data that cannot be seen or modified by users when a form is submitted. For example, the ID of the content that is currently being ordered or edited, or a unique security token.
The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.
In case of Hidden Form Field a hidden (invisible) textfield is used for maintaining the state of an user. In such case, we store the information in the hidden field and get it from another servlet. This approach is better if we have to submit form in all the pages and we don't want to depend on the browser.
Would use prop()
method since required
is a property. Once you remove the property then if user toggles so the become visible again have no current mechanism to track where they got removed.
For this reason I suggest you add a class required
to all the inputs that have required
property.
$('.required').prop('required', function(){
return $(this).is(':visible');
});
This will loop over all of the class required
and adjust property based on visibility
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With