I have a form in which there are two sections.
There are three possibilities for how it is displayed and they are:
There are editors in both sections that have the following settings:
.Required(true).ValidatorOptions(m => m.OnSubmit(true).KeepFocus(ValidatorKeepFocus.Never).FormSubmit(true))
The issue is that they shouldn't be validated if they are hidden. However, I'm seeing that the hidden fields ARE showing the red "This field is required" message when the form is submitted. It shows up in the very top left corner of the screen and isn't associated with any field visible on the screen.
I am using:
The current required message is from a textEditor item.
How can I set the editors to ignore the "Required" flag when hidden on the form?
Thanks,Tony
FYI, I am hiding the section with jquery, similar to this:
<script type="text/javascript"> $(document).ready(function () { var condition1 = @Model.ID1; var condition2 = @Model.ID2;
if condition1 == 0) { $(".Section1").hide(); } if condition2 == 0){ $(".Section2").hide(); } });</script>
In my MVC3 application the events are not being fired with the newer version of the MVC dll (version specified above).
Your test worked fine on my machine though.
Hi Tony,
It should be no difference between simple html and Mvc application. You may look at generated source in browser and probably find same things as you would write them into html manually.
Try to check if by the time when you assign validation option/event, corresponding editor/validator associated with element is already created. For example,
alert('validator:' + $('#date1').data('igValidator'));
$('#date1').igValidator('option', 'validation', function (evt, ui) {...});
If alert will show null or undefined, then adding event handler to "date1" at that time will fail (or create dummy parallel validator).
You also may try to use "bind" or validatorOptions as I provided in previous sample. Example with bind:
$('#date1').bind('igvalidatorvalidation', function (evt, ui) {...});
In any case, a statement related to adding extra options/events to existing editor/validator should be performed (while debugging) with a check if corresponding widget was already created. While checking for existing widget you should use exact name. For example, if you originally created "date1" as igEditor, then you should not use check for igDateEditor or similar, but only check for "igEditor". If you are not sure which widget is actually created, then you may look at generated html and find name of widget created for a specific field-id.