Adding jQuery validator rules to dynamically created elements in ASP

后端 未结 3 948
面向向阳花
面向向阳花 2020-12-02 13:15

I\'ve got some dynamically inserted form fields on a page in an MVC3 project. Normally we would add the jQuery validation server-side, but in this case we can\'t (multiple

3条回答
  •  感动是毒
    2020-12-02 14:20

    I think you had something more simple wrong - like your find('.date') wasn't actually finding anything. Because otherwise, your code looks quite reasonable to me. Here is an example of it working as you expected: http://jsfiddle.net/ryleyb/LNjtd/

    I was able to validate the code correctly with this:

    $('form fieldset')
        .append('
    New Field: * Also required') .find('input[name="newField"]').rules('add', { required: true, messages: { required: 'New field is required' } } );​

提交回复
热议问题