Welcome Guest, Not a member yet? Register   Sign In
jquery form validation - how to validate dinamically added form?
#1

[eluser]SPeed_FANat1c[/eluser]
Ok, I make a form this way:

Code:
$('a.add').live('click',function(){
        
         $('.links').empty();
         $('.add').addClass('grizti');    //pakeiciam klase ir uzrasa
         $('.grizti').text('Grižti');
         $('.grizti').removeClass('add');
        
         //generate form
         $('.links').html('&lt;form id = "new" action="'+ CI.base_url + 'admin_/nuorodos/enter_new" method="post"&gt;&lt;h3>Nauja nuoroda</h3>' +
                
                 '<label>Nuoroda*: </label>&lt;input type="text" name = "link_new" value="http://" /&gt;&lt;span class = "errorSmall error_link"></span><br />' +
                 '<label>Trumpas apibūdinimas: </label>&lt;input type="text" name = "descr_new" value=""  /&gt;' +
                 '<br><br>&lt;input type="submit" class = "submit" value="Išsaugoti" /&gt;&lt;/form>');
        
        
        
         return false;
     });

And the validation code;

Code:
$("#new").validate({
         submitHandler:function(form) {
        
         form.submit();
        
        

        },
        rules: {
             link_new: {
              required: true,
              maxlength: 1000,
              url: true
              
            },
            descr_new: {
                maxlength: 300
            }
        },
        messages: {
            link_new:{
                required: "Neįvedėte nuorodos"
            }    
        }
});

So the first thing is - it does not validate url. When I tried to make the same form in view without need to click on a link with class "add" then it validates. So it does not validate only when I add it dinammically. Anybody knows how to solve this?

And anoter thing is - how to stop it from going to submit page when I click submit button? I don't want it to go to page - ajax should post the data from input fields.




Theme © iAndrew 2016 - Forum software by © MyBB