Hi speedpacket,

> First of all thanks for taking the time to trying to understand me ;)
> Basically what I'm trying to do is the following.

I think this forum is done for that :))

> Whenever I want to add special behaviour to elements on the form, I
> add classes to the element, or add (I know this isn't compliant, but I
> have yet to find a better way) custom attributes, for instance:
> <input type="text" name="nameID" id="nameID" value="blablabla"
> validation="{required}"/>

I see at least two better way:
first use the new prototype Element.storage, so you should keep
outside the DOM the private information.
But as you'll have to walk through the DOM after to reach each element
and find if some attribute is set,
I definitelly think to the second solution: Use an object where you'll
store each private property for each element.
Depending on how you'll walk the DOM, it could be something like:

var myProperty={
    'elementId_1':'set your parameter here in an object, array, ...
depending on what kind of property you'll need',

So that you'll have no more to walk through the DOM, but just have tio
iterate on myProperety object.

> I attached an elementInitialisation() function to the onload of the
> document.
> Once the document loaded, I have one function that does the
> initialisation on the element.
> I would loop over all elements that require initialisation in some
> way, and call the initialiseElemen(el) method.
> In that element, I do all checks (does the element need validation
> added, does it require extra behaviour, ...) and I modify the element
> adding the desired behaviour.  This works fantastically...

so this part is OK :))
my contribution is just a way to do this !

> Unfortunately however, I also update the contents of my page using
> ajax on several occasions which might also add elements to the
> document that would require initialisation.  These elements would need
> to be going through the initialiseElement(el) function as well...

In this condition, it could be hard to maintain to use the same object
to store original element and the one added with AJAX.
But if you modify a little bit your initialiseElement(el) function to
initialiseElement(OBJECT), than your first call will pass the original
object that could create some other DOM element and each onComplete
callback of the AJAX request will call the initialiseElement()
function with a newly created object only containing element that were
created inside each AJAX request.

this could be a way to do what you'll need. What do you think ?


> On Dec 7, 1:06 pm, david <david.brill...@gmail.com> wrote:
> > Hi speedpacket,
> > > Is there a way to observe the dom and automatically run newly created
> > > elements through the initialise function?
> > could you please explain a little more what is expected !
> > Or perhaps if you have some available code ?
> > --
> > david
> > On 4 déc, 13:19, "speedpac...@gmail.com" <speedpac...@gmail.com>
> > wrote:
> > > Hello there,
> > > I have another question that I hope someone can give me some insight
> > > too...
> > > As I want all javascript code to be in a seperate file, I wrote a
> > > function "initialiseElements" which literally takes an element and
> > > initialises its behaviour based upon some attributes (classname for
> > > instance).
> > > Basically it takes the elemen, checks whether el.readAttribute
> > > ("isInitialised") == false, and in that case processes the element
> > > (adding tooltips for action images, adding onclick behaviour,
> > > onmouseover behaviour, add validators to inputs and so on...)
> > > When processed we set el.writeAttribute("isInitialised") = true so
> > > that it will only process one element a single time...
> > > I found this way of working to be going great, and I basically call
> > > the initialiseElement method for each element upon loading the form,
> > > making it a very generic process...
> > > However (yes, there is a but!!!), I do have an issue of course when I
> > > cal some ajax to update the content; in that case I need to initialise
> > > the elements that have been added...
> > > Is there a way to observe the dom and automatically run newly created
> > > elements through the initialise function?
> > > Would this be a good approach?
> > > How do you guys deal with stuff like this?
> > > thanks so much in advance again for your much appreciated feedback.


You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to