Login Register

Project Idea: Dynamically generated forms from JSON representations

Hi,

I am Bharadwaj, final year student at the Indian Institute of Technology, Madras. I have been using dojo for the past 4 months on a project for the front end of a business system software, and I have found answers for almost all of my UI requirements within dojo; hats off to you guys. This post contains my idea for the GSoC 2008 for dojo.

I am interested in contributing to the dojo project as a part of GSoC. In particular, I would like to work on a problem that I faced during the development of the front end in the project I mentioned before. This required dynamically generated forms based on certain criteria. My idea therefore is to draw up a JSON representation of a form that needs to be displayed to the user, and have it parsed by a form generator, existing as a part of dojo, to dynamically create the required form elements at the respective places with the intended functionality.

For example, consider a page for creating a profile with different form elements such as a textbox, a radio button etc. Now, for editing the profile, we require the same form, but with the addition of the different form element being already set. In other cases, there may be a few elements which are not editable, but need to be visible. Or, maybe, we want to hold the same profile form, but with an additional few elements for user with higher privileges. Or, finally, there might be two totally different forms, both of which, however, relate to profile creation.

What we see here is a variation of a common theme. It would be a terrible waste to duplicate the functionality in order to reflect the small variations in an otherwise single unit. If, in this particular example, there was a way of collecting all these variations in functionality in a consistent manner and implementing these changes into a common baseline HTML markup using dojo, then it would reduce the unnecessary duplication described above.

The idea I have just described has the following advantages:

1.The server is free to specify the form elements and functionality required from the page, independent of the layout of the page. All the server needs to provide is a JSON representation of the form elements that need to be present, along with their intended behavior. It is up to the form generator to create plain-vanilla or dijit form elements and place them in the appropriate locations with the intended functionality.

2.Since the JSON representation is available in the browser, it can be modified to reflect any changes to a form’s design and immediately refreshed to visualize the changes, without requiring any trip to the server or any fancy DOM manipulation. An immediate application of this capability would be in a dojo IDE. Another possible application could be in a situation where the number of form elements required is unknown, and is set by the user.

3.As mentioned earlier, small variations to an otherwise uniform form is captured in the JSON representation, thereby allowing for these variations come under a single logical unit.

The dojo toolkit provides various enhanced form elements which incorporate features that go beyond plain-vanilla form elements – in particular, validation and event handling. Furthermore, there are complex elements which are not a part of the traditional form element set – such as Trees and Grids. Since the Form Generator will be a part of dojo itself, the generation of the form will be a simple matter of making use of these existing form elements and constructing the form required. However, before this can be done, it is necessary to come up with a JSON representation of the possible complexities in a form which can eventually be used by the Form Generator to generate any form. This would be similar to constructing a Tree from a JSON representation of a tree. Taking the Tree analogy further, it might also be possible to construct subforms within forms which communicate a subset of the user’s input to the server without the parent form being submitted in it entirety (think country-state-city drop down boxes), and yet forms a part of the whole parent form.

Furthermore, validation parameters can be specified in the JSON representation and can be converted into the corresponding dojo validation attributes, which would result in automated validation for the corresponding form elements. Also, we can allow for a form to have its elements in different sections of the same page (say a textbox in a left column, a radio in a right column and a submit button in the center) and still function as a coherent whole – thereby allowing for the layout of the form to be completely separate from the functionality or organization of the form. This adds a lot of flexibility for both the developer and the user in designing the forms. Finally, submission of the forms can also be handled by the dojo AJAX methods or, if the user requires, in the traditional fashion.

This is a rough overview of the idea I have come up with. I am in the process of preparing a small example of how I would go about doing this for, say, two or three widgets as a part of the full proposal. I would like to know your suggestions and ideas regarding this so that the idea can be fine-tuned.

Thanks in advance for your contributions.

Bharadwaj

I like it. Another thing to

I like it. Another thing to consider would be "form series", or "wizards" based on your defined JSON object. For instance a use would fill out a username and password in the first step, the JSON object would reference a callback / submit method, and a round-trip to the server to determine the next best step in the form to show to the user (eg: "we still need your billing address:" ) ... Have a Form Factory of sorts like this would also benefit long-lived pages, as you would theoretically be able to maintain your own cleaup of all the elements used, and have better validation control / UX overall.

Keep it up.

This idea has been realize in our project

hi,Bharadwaj
You really get a wonderful idea. I think you can consult about this project to refine your idea. Click here.

Thanks for the inputs

Thanks for the inputs. I have incorporated the suggestions into my proposal. I would also like to know if there are any other suggestions, now that the deadline has been extended to April 7th.

Bharadwaj

interesting

This is an interesting idea. Some people have also asked for forms generated dynamically from dojo.data, although I'm not sure what that means exactly (is there a single item in the datastore that represents a form, or a bunch of items each of which represents a field?). But probably starting with a custom JS object to represent the form is better.

regarding data, etc.

So with the help of Owen Williams, I spent some time looking into some of the pre-existing syntaxes for doing things like this (XForms, etc.) and while it's clear that we need a "form widget" that handles grouping and larger-chunk validation, there's also a question around repeating items and "relevence".

Relevence in the sense of XForms is what is used to determine if one section of a form is visible or hidden, and it's usually expressed in systems like this as a rule that relates the state of some input or output to the display state of another. The upshot is that when the state of an input changes, the relevence rules need to be re-calculated. This isn't too dissimilar to what the Html renderer for dojox.dtl needs to do internally to cope with context object state changes for calculating when a property or chunk of UI needs to be changed/updated.

Therefore, I might suggest that any project which is going to start tackling this problem look at the dojox.dtl.html renderer as the basis for any such system. Since context objects and their JSON representations seem relatively compatible (which leaves the widget to provide default view templates) and since the dtl Html renderer already handles diffs, it may be possible to bootstrap relatively complex form on the back of a simple syntax which uses pre-existing components to a large degree.

Regards

--
Project Lead, The Dojo Toolkit
President, The Dojo Foundation