My preference would be to provide hooks for JS validation only. I
prefer using MooTools as my JS library, but there's no doubt many
would prefer JQuery, Script.aculo.us or many other flavours. Adding ZF-
specific JavaScripts would be IMO a waste of time.
The difficulty I see with ZF providing JavaScript libraries is that it
is yet another layer of complexity to introduce (compatibility,
maintainability, potential duplication of code, etc.). I've already
used HTML_QuickForm which is a great example of how _not_ to handle JS
validation (I only still use it as I'm waiting for Zend_Form to mature
before I replace it). QuickForm's JavaScript is definitely not OO and
it is a right pain to add custom validators. Whilst I'm sure there's a
number of better solutions that could be added to ZF, I'm not
convinced that you'd want to. The minute you start tying a specific
script solution to something like a form validator it inevitably ends
up forming a tight integration with the framework. And that means
adding your own JS libraries to a ZF solution could be difficult (see
Drupal as an example).
An idea I had rattling around in my brain was to leverage a form
validation controller to provide client-side validation. All a
developer needs to do is add a hook from the Zend_Form 'onsubmit'
event to their JS library of choice and have it use a remote HTTP
request to the validation controller. A single digit boolean response
could indicate a successful submission and a response with an encoded
array of id's and strings would allow a means to retrieve all the
incorrect form elements.
Whilst this approach is limited by browser support (IE6+, FireFox
1.5+, Safari, etc..) it does reduce the amount of code required in the
backend and it certainly removes a lot of ugly inline validation
scripts - many of which you may prefer to keep hidden from the end-
user anyway.
Besides AJAX validation(/filtering), maybe some autmatic JS validation
code would be nice. E.g. regex validation works well on server and
client side. And all the expressions would be the same. Just some
extra functionality to pull in the JS code into a validation function.
Not sure how easy it would be for element dependencies but should be
possible as well. All the existing validation helpers should be easily
adapted to provide some JS validation. Thoughts!!!
Gunter
Not yet; I hope to have a full proposal out later in the week; more
on
that below. The ideas I'm looking at now are:
* "sectioned" forms -- i.e., forms that have grouped items
* Element dependencies (elements whose validations depend on the
values of other elements)
* Multi-page forms
* AJAX interaction:
* Validating single or multiple elements via AJAX
* Autocompleters
--
Simon Mundy | Director | PEPTOLAB
""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
PeptoLab will be closed:
Saturday 15th December through until Monday 17th December
Saturday 22nd December through until Wednesday 2nd January
For urgent requests, please call 0438 046 061
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
4124
http://www.peptolab.com