| Issue 9: | Conditional modal on form validation | |
| 2 people starred this issue and may be notified of changes. | Back to list |
Hello,
I am using a form submit to open an ajax nyromodal, which works fine if I
just include something like this: $("#myForm").nyroModal({width: 420 })
However, I want to add validation to the form and only submit in the valid
case. When I do something like this
$("#myForm").nyroModal({width: 420 })
$("#myForm").submit(function() {
if (validation conidtions) {
$("#myForm").submit();
}
else {
alert("error");
return false;
}
});
the nyroModal opens regardless (the event is not canceled in the error
case).
If I don't call nyroModal until validation passes, the modal doesn't open
and a normal submit happens (full browser) in the valid case:
$("#myForm").submit(function() {
if (validation conidtions) {
$("#myForm").nyroModal({width: 420 }).submit();
}
else {
alert("error");
return false;
}
});
Any thoughts?
Apr 24, 2008
#1
steveda...@gmail.com
Apr 24, 2008
You can do it by using nyroModalManual like that:
$("#myForm").submit(function() {
if (validation conidtions) {
$("#myForm").nyroModalManual({width: 420 })
}
else {
alert("error");
return false;
}
});
I didn't test, but it should work.
Let me know if everything is ok
Status:
Fixed
Labels: -Type-Defect Type-Other
Apr 25, 2008
Thanks for thinking about this. Unfortunately, this does not work. The submit event is trapped properly, but in the valid condition, the modal starts to draw, then the form posts as normal and takes over the entire browser. Take a look at http://38.99.15.19/test/nyro/demo.php where I have modified your first form to use this validation. I've tried variations, but whenever I seem to trap the form's submit event myself, things don't work quite right.
Apr 26, 2008
ah yes...
I forgot to return false or use the preventDefault() function.
Here is the code which should work anyway:
$("#myForm").submit(function(event) {
if (validation conidtions) {
$("#myForm").nyroModalManual({width: 420 })
}
else {
alert("error");
}
// We want to stop the form submit anyway
event.preventDefault();
return false; // Not required as we already use the preventDefault function,
but I prefer do it to be sure
});
Apr 26, 2008
Thanks. Yes, I see how the preventDefault is needed. However, now take a look: http://38.99.15.19/test/nyro/demo.php The form's action is now getting wiped out.
Apr 27, 2008
That was a bug, fixed in the version 1.2.2 that I just released. I also put your example in the project homepage and the demo.php include in the relase. Thanks for your report. Don't hesitate to send a link of the live site ;) |