views:

102

answers:

3

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 :

  • I could use live support to bind the change event over inputs, like this

        $("#adresseLivraisonPro").live('change',function(e){
        $("#adresseLivraisonPro").validate({
    

    But this makes my form validated if and only if user changes inputs...

How would you surround that problem ?

+1  A: 

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.

Vincent Ramdhanie
My bad, I did this befor, but, in order to keep things clear, made an external function... that I declared after the ajax callback... silly me... Thanks a lot !
pixelboy
+1  A: 

apply the validation when you inject the form

mcgrailm
A: 

Assuming you do something like

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