I currently have an app that is using a twitter bootstrap modal box. The div that the modal is displaying is getting loaded with JQuery from /users/new action. Everything works great if the user enters valid data in the modal box submitted but if the data sent to params does not pass validation the controller redirects back to the new action but this time outside of the modal box and the page that user was previously on is gone, which sort of defeats the purpose of having the modal box to begin with.
I have looked at Live-Validation and other javascript based client-side validations. These are an option but I would much prefer being able to use my existing validations in the users model for consistency’s sake. I there a good way to make the modal box persist while the form is being submitted and to make the controller reload the page within the modal with the error_messages?
Thanks
Are the error_messages loaded into the modal using javascript? If so, you could have the page check to see if there are error_messages on load, then pop open the modal box if there are any. This won’t save any input from the modal, but it will pop it open.
Alternatively, you could implement some light client side validation on top of your current model. However, how light it would be is dependent on how picky your model is regarding its input. If it’s very specific what it will accept/reject, it would be much harder to verify consistency, and having something get through client-side validation only to bounce back and say it was invalid isn’t always pretty.