I'm currently working on a form which can contain multiple instances of a sub-form. The main entry 'publication form' contains multiple instances of a sub-page 'publication.' I'm doing this using AJAX, and every time the user clicks an 'add row' button, they get a new sub-form item, called from a custom view.
Now, every time the 'add row' button is clicked, a javascript counter is incremented, and then that value is sent to a controller, which puts it into ViewBag, and sends it to the view file. For each item to be treated differently, I use this viewbag counter to increment it's name and id, for example:
<input id="pubDetails@(ViewBag.Upto)" class="text-box single-line" type="text" value="" name="pubDetails@(ViewBag.Upto)" data-val-required="The Full Publication Details (Include ISBN, Web addresses etc) (include all authors) field is required." data-val="true">
<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="PubDetails@(ViewBag.Upto)"></span>
This view file is not part of it's own form, but rather the fields are being passed into the form of the master page.
The issue now, is that client side validation it doesn't work for these fields, as I've changed their IDs! Is there some way to specify which IDs get which kind of validation, outside of the default? Maybe something like
<input validationID="pubDetails">
or any way of re-pointing the validation at the appropriate field ids?
Thanks!
$.validator.unobtrusive.parse("#ID");
– Mohamad Bataineh May 30 at 5:34