BeFruit

Wednesday, July 4, 2007

Form'n'Field jQuery plug-in published

After long nights of fine tuning and restructuring, the first public version of the Form'n'Field plug-in for jQuery is available.

It helps JavaScript developers to handle client-side forms by giving access to field values in real types and not only strings as returned by DHTML. Why should the value of a checkbox be a string? Isn't it more natural that it is a boolean?

The same applies to listboxes. I often generate listboxes when item names are labels and item values are IDs from by database. Why would I have to convert those IDs from and to strings? I want them to be integers, and that's what the Form'n'Field plug-in does.
But what is the most advanced feature about this plug-in is how extensible it is. You can add your own input type (like a date input with pop-up calendar) easily. Or your complex data type (a JavaScript structure) can be associated with any existing input and handle type conversion and validation.

This plug-in is currently in production in my organization, and I hope that people will understand its value and constructively participate in its development.

Labels: ,

Thursday, May 31, 2007

Handling forms in the browser

With the increased use of Ajax, form handling has evolved. Even if user needs are the same, the developer has new constraints faced repeatedly. There is obviously a need for a JavaScript library solving the following points:
  • filling a form with data. Now that data is dynamically loaded with Ajax, the HTML form is empty and data, often provided as a complex object, has to be transferred, types converted, etc.
  • field validation is not a new problem, but calling a server-side validation function on each user action is not a fast enough solution. Calling it when the field loses focus is too late as it forces the user to get back.
  • extracting data on user submit, converting them again to a complex object to be sent by Ajax.
Doing these steps for each form increases the code size and the potential bugs, and quickly becomes boring...

As I am working with jQuery, I started looking at existing libraries, and some of them actually solve some of these points, but partially.
The first library to look at is the "official" Form plugin. Unfortunately the main aim of that library is only to submit forms with Ajax instead of a normal POST request. Sending data with Ajax is for me a separated task, as all forms are not necessary sent to the server.
Other libraries offer form validation, like the recent ValidationAide, but are either poorly isolated from other functionalities or reduced to a set of regular expressions.

As often when a need is not satisfied, I decided to build my own library with the following features:
  • handling of form content filling and reading
  • field validation
  • separation between form and field functions
  • no functions for submission (rather using jQuery+JSON functions or AjaxPro)
  • no superfluous features
  • full customization available, with lot of default behaviors
and naturally the library will be offered to the community.

Labels: , ,