jQuery validation fails when using KnockoutJS and Jquery dialog

前端 未结 2 633
闹比i
闹比i 2020-12-29 17:31

I have a form which is rendered using html.RenderAction in MVC3.

Outside of this I have a jquery template used with knockout. The model is rendered correctly into t

相关标签:
2条回答
  • 2020-12-29 17:43

    I have looked into the code of jQuery validate and I think it doesn't work for dynamically added forms (which what Knockout does).

    Take a look at this > Jquery Validation Plugin, dynamic form validation

    You need to call the validate() method in a an event handler registered using the jQuery live() method. The live method links to all the dynamically added elements as well.

    Let me know if it works.

    0 讨论(0)
  • 2020-12-29 17:44

    Try calling $.validator.unobtrusive.parse(yourFormElement) to get your data- attributes related to validation parsed.

    You could trigger it like:

    <div id="dlgAdd" data-bind="template: { name: 'editTemplate', data: selected, afterRender: hookUpValidation  }">
    </div>
    

    then, hookUpValidation would look like:

    hookUpValidation: function(nodes) {
        $.validator.unobtrusive.parse(nodes[0]);
    }
    
    0 讨论(0)
提交回复
热议问题