pixelboy
pixelboy

Reputation: 729

jQuery plugin validate() : apply plugin to ajax injected form

My issue here is quite simple : i'm trying to use the jQuery validate plugin to a form that gets injected after certain user actions.

My problem mostly is that :

How would you surround that problem ?

Upvotes: 1

Views: 736

Answers (3)

jitter
jitter

Reputation: 54605

Assuming you do something like

... user action ...
... retrieve formhtml somehow ajax/stringconcat ...
$("#formcontainer").html(formhtml); //inject form
$("#formcontainer form").validate(); //wire validation to form

Upvotes: 0

mcgrailm
mcgrailm

Reputation: 17640

apply the validation when you inject the form

Upvotes: 1

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

You can use the callback function of the AJAX call to apply the validation to the form.

    $("myformarea").load("urlof form.php", function(){
            $("The Form").validate();
    });

So the validation is applied after the form is loaded.

Upvotes: 1

Related Questions