0

Hi,

I have a button:

<input class = "save" type="button" value="Išsaugoti" />

As you can see the type is not submit, it is just button. This is because I want to not allow submission if javascript is disabled.

To submit I run this code:

$('input.save').click(function() {
		
		$('form').attr( 'target', '' );
		$(".edit").validate({
			 
			
			rules: {
			 	input_pavadinimas: {
			      required: true,
			      maxlength: 20
			    },
			    
			    text: {
			    	required: true
			    }
			    
			},
			messages: {
				input_pavadinimas:{
					required: "Neįvedėte pavadinimo",
					maxlength: "Maksimalus ilgis - 20 simbolių"
				},	
				
				text: {
					required: "Neįvedėte teksto"
				}
			}
			
		}
				
		
		);
		
		document.myform.submit();		//myfor - formos name atributas
	});

But the validation doesn't work.

When the button type is submit and I run this code

$(".edit").validate({
		 
		 submitHandler:function(form) {
		
		 form.submit();
		//document.myform.submit();		//myfor - formos name atributas
		 
		 
		
		},
		rules: {
		 	input_pavadinimas: {
		      required: true,
		      maxlength: 20
		    },
		    
		    text: {
		    	required: true
		    }
		    
		},
		messages: {
			input_pavadinimas:{
				required: "Neįvedėte pavadinimo",
				maxlength: "Maksimalus ilgis - 20 simbolių"
			},	
			
			text: {
				required: "Neįvedėte teksto"
			}
		}
		
	});

validation works perfectly.

I don't find in google and in documentation how to run it when button is not submit type :( Can you help me?

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by McLaren
0

Found the solution:

$('input.save').click(function() {
        
        $('form').attr( 'target', '' );
        valid = $(".edit").validate({		
             
            rules: {
                 input_pavadinimas: {
                  required: true,
                  maxlength: 20
                },
                
                text: {
                    required: true
                }
                
            },
            messages: {
                input_pavadinimas:{
                    required: "Neįvedėte pavadinimo",
                    maxlength: "Maksimalus ilgis - 20 simbolių"
                },    
                
                text: {
                    required: "Neįvedėte teksto"
                }
            }
            
        }
                
        
        ).form();
        if(valid)
        	document.myform.submit();
    });
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.