0

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!

2
  • $.validator.unobtrusive.parse("#ID"); Commented May 30, 2014 at 5:34
  • Thanks! Where do I add this code in? Is this meant to be run on each id of the elements I want to validate, in like a separate js function? Thanks! Commented Jun 2, 2014 at 4:11

1 Answer 1

0

Since you're not using Ajax.BeginForm(), I'm pretty sure you need to use $.validator.unobtrusive.parse("#ID); to specify that there's validator information you want parsed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.