knockout.js - jQuery Validate on form that is destroyed/recreated with Knockout -


i have form within jquery ui dialog created , destroyed every time open , close dialog (as part of knockout custom binding). problem jquery validation works first time dialog opens, doesn't work if close , reopen dialog.

here simplified snippet of form within jquery ui dialog:

<div id="product-panel" data-bind="dialog: { autoopen: false, destroyonclose: true }, showdialog: $parent.selectedproduct">     <form data-bind="submit: saveme" id="product-form" method="post">          <label>             name             <input type="text" id="productname" name="productname" data-bind="value: productname">         </label>          <button type="submit" class="button">save</button>     </form> </div> 

i'd show contents of ko.bindinghandlers.dialog too, don't think associated problem. 1 thing know dialog custom binding configures jquery ui dialog destroyed whenever closed.

i use jquery's on() method rebind validate form whenever dialog opens again:

$("body").on("dialogopen", "#product-panel", function(event) {      $('#product-form').validate({         rules: {             productname: {                  required: true             }         }     }); }); 

any thoughts? oh, , don't want use knockout validation (for other reasons).

jquery 2.0, jquery ui 1.9.2, jquery validation 1.11.1, knockout 2.2.0

why destroying , re-creating want open->close->open->close->etc?

if jquery validation working when first opens, don't destroy it since you're going need use again anyway.

destroyonclose: false 

and if never destroy it, not have call .validate() again, can rid of this...

$("body").on("dialogopen", "#product-panel", function(event) {      $('#product-form').validate({...}); }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -