After making a field not required through JavaScript, how does one force it to re-validate?
I have two mutually inclusive fields--they are not always required, but if there is a value in one, the other needs a value as well. The code below is working to make them required or not:
$('.LodgingRate input,.Lodging input').blur(function(){ if(($('.LodgingRate input').val() > 0 || $('.Lodging input').val() > 0) && !$('.Lodging .cf-required').length) { $('.LodgingRate input,.Lodging input').prop('required',true).attr('min',0.01).parent().siblings('.cf-label').append('<span class="cf-required">*</span>'); } else if(!($('.LodgingRate input').val() > 0 || $('.Lodging input').val() > 0) && $('.Lodging .cf-required').length) { $('.LodgingRate input,.Lodging input').prop('required',false).removeAttr('min').parent().parent().find('.cf-required').remove(); } });
The only problem I have is when the user:
- provides a value in one field (making both fields required)
- triggers the "Value is required" message in the second field
- then clears the value from the first field (making neither field required).
This leaves the error message and red highlight on the empty second field, which is no longer an error.
Laserfiche Forms Professional Version 10.3.1.635