BeFruit

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: , ,

1 Comments:

Post a Comment



<$I18N$LinksToThisPost>:

Create a Link

<< Home