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>
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.
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.
Can you tell what exactly does not work, validation event is not raised or "return false" has no effect?
I wrote a sample, which has 2 editors and one of them is located in a hidden container. Both editors use same validation function and that function skips validation of editor, which is invisible (has no offset).
I attached that sample. It does not use any local resources, so, it can be tested from any location. I hope it mimics your application. Please check how it works: click submit with different combinations of values in editors, visibility of editor in container, etc. I hope it will work as it was designed.
When I upgraded to 12.1 of Infragistics.Web.Mvc (3.12.1.2059), this approach no longer worked. I have since gone back to 11.2 (3.11.2.2060) and it is working again.
If you know the right way of doing this in the newer versions, please let me know.
Thanks,
Tony
This works well. Thank you.