Reputation: 20163
I'm trying to make a function to activate a 'form' for a 'field'.
function validacion_coment(form){
$("#"+form).validate({
rules: {
texto: "required"
},
messages: {
texto: "<?php echo get_texto_clave('error_validate_empty'); ?>"
}
});
}
But it doesn't, is there something special with validate() for dialog?
-edit- no error in Firebug.
WHEN I CALL IT
function nueva_respuesta(id){
$("#pop").load('./includes/router.php?que=nueva_respuesta&id='+id);
pop_up_extra("pop","funcook.com",400,350);
validacion_coment('respuesta');
return false;
}
Upvotes: 1
Views: 624
Reputation: 34038
This will bind the validation function to all of the forms on your page at pageload time.
$(document).ready(function() {
$('form').each(function() {
$(this).validate({
rules: {
texto: "required"
},
messages: {
texto: "<?php echo get_texto_clave('error_validate_empty'); ?>"
}
});
});
});
If you want to add validation for a specific form, try this:
$(document).ready(function() {
$('#myIdOnMyForm').validate({
rules: {
texto: "required"
},
messages: {
texto: "<?php echo get_texto_clave('error_validate_empty'); ?>"
}
});
});
NOTE: These events must be defined before you attempt to submit the form. Pageload time is a good time to bind these events.
To bind the validation after loading HTML on the page, make sure the validation event setup is invoked in your AJAX load calback so that it doesn't try to bind it before the response has been received:
$("#pop").load('./includes/router.php?que=nueva_respuesta&id='+id, function() {
pop_up_extra("pop","funcook.com",400,350);
validacion_coment('respuesta');
return false;
});
Upvotes: 2