I found this question on another forum where it didn't get any answers. I thought it was a good question worth asking here. I'm pasting it here word for word.
Hi guys, I've got a pie in the sky idea, and I'm just wondering if it's even remotely possible, or if I should give up and try something else.
I've got a bunch of Zend_Dojo_Form forms with a bunch of custom validators on the Zend side - they work fine, the form errors out when values are incorrect, it's all working exactly as you'd expect, however, what I'd also like is for the same validators to work on the Dojo client side of the form - but without having to completely re-implement them, validator by validator.
I understand that at its simplest level, the Dojo isValid method doesn't know or care about the application behind it, and indeed for it to even be able to get access to the errors in the application it'd have to attempt a submit, which isn't what it's meant to do, but has anyone tried a system of something like:
- override form onSubmit to add our code
- test Dojo isValid()
- if the Dojo side is happy, AJAX submit the form
- if successful, which would be returned i don't know how, then forward on to the appropriate page
- if not successful, then (and this is where it gets tricky I guess) pass back enough data to know what field errored out, what the error was, and then call enough of the Dojo isValid internal guts to make the form look like it didn't validate?
Sorry to just be airing ideas like this, I just figured it might be really useful if we could come up with a way to sort of globally add custom validators to our forms that work both client and server side, without having to implement them uniquely on both sides.
Meh, dojo :(
Use Jquery :)
Look at this, it's awesome: Ajaxify Your Zend_Form Validation with jQuery