Mootools: injection and acceptance

I want to dynamically add some pre-configured HTML elements when using the 'click' event with mootools.

Therefore, I can make it work with my basic knowledge, although it is not very elegant. I have encoded this so far ...

This is my preconfigured element with some text, a class name and some event, so I want the events to be added when it is inserted into my container:

        var label = new Element('label', {
            'text': 'Label',
            'class': 'label',
            'events': {
                'click': function(el){
                    alert('click');
                }
            }
        });

Here is my function that adds label-Element:

        function addText(){
            $('fb-buildit').addEvent('click', function(){                   
           row.adopt(label, textinput, deletebtn);
            $('the-form').adopt(row.clone());
            row.empty();

    /*
    label.clone().inject($('the-form'));
    textinput.inject($('the-form'));
    deletebtn.inject($('the-form'));
    */

            });
        }

The second part, which uses injection, also works, but my click event, which fires an alert ('click'), works there. The accept method does not add any event to my label object when it is inserted in dom.

- . , adobt "" .

.

( ^^)

+5
1

label.clone().inject, row.adopt(label), row.adopt(label.clone()) -

..clone() cloneEvents - .

var myclone = label.clone();
myclone.cloneEvents(label);
row.adopt(label);

, , . mootools uid, label = 1, label.clone() → 2, label.clone() → 3 ..

Storage[1] = { events: ... } .. . , .cloneEvents()

.clone(), , ORIGINAL .

.

formElement.addEvent("click:relay(label.myLabel)", function(e, el) {
    alert("hi from "+ el.uid);
});

, , , label class myLabel formElement, .

+5

All Articles