This project is archived and is in readonly mode.

#577 ✓invalid
pwieland

Element.set needs a case for 'hash'

Reported by pwieland | January 27th, 2009 @ 06:04 PM | in 2.0 (closed)

'version': '1.2.1',

'build': '0d4845aab3d9a4fdee2f0d4a6dd59210e4b697cf'

Element.set does not have a case for hashes, so this doesn't work:

var props = {'text': 'Option A', 'value': 'a'}; var option = new Element('option',$H(props)); // creates

instead of Option A

Proposed solution: add:

        case 'hash':
            for (var p in prop.getClean()) this.set(p, prop[p]);
            break;

to

Element.implement({

set: function(prop, value){
    switch ($type(prop)){
        case 'object':
            for (var p in prop) this.set(p, prop[p]);
            break;
        case 'string':
            var property = Element.Properties.get(prop);
            (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
    }
    return this;
},

});

Comments and changes to this ticket

  • gravydish (at gmail)

    gravydish (at gmail) January 29th, 2009 @ 04:04 PM

    Perhaps a cleaner approach:

    @@@javascript set: function(prop, value){

    switch ($type(prop)){
        case 'hash':
            prop=prop.getClean();
        case 'object':
            for (var p in prop) this.set(p, prop[p]);
            break;
        case 'string':
            var property = Element.Properties.get(prop);
            (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
    }
    return this;
    
    

    },

    
    
  • Fábio M. Costa

    Fábio M. Costa January 30th, 2009 @ 02:59 AM

    since hash is getting out of the core i dont think this is going to be done. but thats a nice code.

  • Jan Kassens

    Jan Kassens November 22nd, 2009 @ 12:25 PM

    • Assigned user cleared.
    • State changed from “new” to “invalid”

    as Fábio said, this ticket doesn't really apply to MooTools 2. You should use getClean if you want to use an Hash in your code.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages