26th June - 1st July

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
silence's picture

In this week (from 26th June to 1st July), one of the primary aims was to develop a framework on client side which implements addWidget(), deleteWidget() etc. The framework should be working directly on the DOM form and JS form object.

Here is a demo of what I am trying to do for the goal. Here are some changes:

  1. Now additions of widgets are reflcted in the DOM form as well as JS form object.
  2. Properties of the widgets can be changed from the 3rd column which shows all the properties for a widget which are described in the form API reference.
  3. A temporary arrangement to see the JS form object is made(It will be removed later). You can click on the heading of second column "Preview" to see a serialization of the DOM form array. Note that this serialization is just for the checking purposes and not something that /includes/form.inc can parse.
  4. Some UI changes necessary for the proper functioning.

Notes:

  1. This demo is just to show what I am trying to do, so I just implemented the textfield and textarea widgets.
  2. The source will be commited by the end of week(when all requirements are fullfilled.). By then, any issues raised here should be cleared.
  3. You can download the source from this link: http://www.freewebs.com/socdemocode/prototype0.5.zip.
  4. If you are looking at the code, please see if the procedure I am following to add an element okay or not. Please see the function: addItem() in functions.js and index.htm.

Also there are a few issues that I am facing right now...any help is appreciated:

  1. I read somewhere that the proper deletion of an key-value pair from a JS Associative array is available only from javascript v1.2 onwards. Is it correct? If yes, How do I handle other cases?
  2. Again while reading sometihng, I found that the order in which the key-value pair are entered in a JS form object "stays" the way it was done initially. So how do I take care of the rearrangements of form widgets? I could think of two ways but I am sure of none:
    2.1 Delete the whole JS form Object and remake it in the new order.
    2.2 Use weight property of the form. (Here the problem comes when I have to assign weights.... How do I assign them? help me!!)

Comments

The demo is looking great!

robertDouglass's picture

=)

Rearranging array items

nedjo's picture

So how do I take care of the rearrangements of form widgets?

This issue has come up on the PHP side as well, see http://drupal.org/node/66183. Maybe in the end parallel methods will make sense?

In both PHP and Javascript, there are splice methods, but they work only with numeric keys. See http://www.devguru.com/Technologies/ecmascript/quickref/splice.html for the Javascript splice method.

When searching for clues, keep in mind that this sort of array is called an "associative array". A reference I came across:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21480690....

Apparently you can remove an array element with delete:

delete form['password'];

I suspect you'll have to write a function manually rebuilding the array, like the patch at http://drupal.org/node/66183 is trying to do.

delete....

silence's picture

Yes That is what I did but is it fine if only js version 1.2 and above support it? I read this somewhere but have no way to check.

If someone can, please check it.

SoC 2006: AJAX Form Builder

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week