You can't, obj.setProperty('selected', 'true'); will just set the value to true. Best you can do is to set _selected to true then with regex you can change _selected to selected,
The Element.js file in MooTools core handles some attributes in a
custom manner. From a programmatic js perspective, I rarely encounter
a need for the HTML attribute. However, I _have_ encountered such a
need: when I want to reset for values to their original state. In this
case, I use:
Starting @ line 540, bools defined boolean attributes (including
'selected') and added a propertySetters function to simply call:
propertySetters[{'selected'}] = function (node, value) {
node[bool] = !!value;
};
This is why you don't see an HTML attribute for the 'selected'
property you are passing.
Element.js could be modified as follows, starting @ line 561, but I'm
not sure if this would break other behavior:
Object.append(propertySetters, {
'class': function (node, value) {
('className' in node) ? node.className = value :
node.setAttribute('class', value);
},
'for': function (node, value) {
('htmlFor' in node) ? node.htmlFor = value :
node.setAttribute('for', value);
},
'style': function (node, value) {
(node.style) ? node.style.cssText = value :
node.setAttribute('style', value);
},
// handle 'selected' in both the javascript and HTML?
'selected': function (node, value) {
node.selected = !!value; // not sure you really need this if you
have the next line(s)
if (value) node.setAttribute('selected', 'selected');
else node.removeProperties('selected');
}
});
I'll defer to others regarding the wisdom of such an override.
Eric
On Apr 23, 9:56 am, "Steve Onnis" <st...@cfcentral.com.au> wrote:
That would mean you would have to set an ID for every option and then reference it after it has been added to the DOM before you could even set the property on it. Kinda dumb yeah?
-----Original Message----- From: Eric Patrick [mailto:epatr...@quandis.com] Sent: Tuesday, 24 April 2012 12:45 AM To: MooTools Users Subject: [Moo] Re: selectbox options "selected"
The Element.js file in MooTools core handles some attributes in a custom manner. From a programmatic js perspective, I rarely encounter a need for the HTML attribute. However, I _have_ encountered such a need: when I want to reset for values to their original state. In this case, I use:
Starting @ line 540, bools defined boolean attributes (including 'selected') and added a propertySetters function to simply call:
propertySetters[{'selected'}] = function (node, value) { node[bool] = !!value; };
This is why you don't see an HTML attribute for the 'selected' property you are passing.
Element.js could be modified as follows, starting @ line 561, but I'm not sure if this would break other behavior:
Object.append(propertySetters, {
'class': function (node, value) { ('className' in node) ? node.className = value : node.setAttribute('class', value); },
'for': function (node, value) { ('htmlFor' in node) ? node.htmlFor = value : node.setAttribute('for', value); },
'style': function (node, value) { (node.style) ? node.style.cssText = value : node.setAttribute('style', value); },
// handle 'selected' in both the javascript and HTML? 'selected': function (node, value) { node.selected = !!value; // not sure you really need this if you have the next line(s) if (value) node.setAttribute('selected', 'selected'); else node.removeProperties('selected'); }
});
I'll defer to others regarding the wisdom of such an override.
Eric
On Apr 23, 9:56 am, "Steve Onnis" <st...@cfcentral.com.au> wrote: > I know it selects it, but the actual HTML it renders i am expecting is
On Monday, April 23, 2012 10:49:25 AM UTC-4, Steve Onnis wrote:
> That would mean you would have to set an ID for every option and then > reference it after it has been added to the DOM before you could even set > the property on it. Kinda dumb yeah?
> -----Original Message----- > From: Eric Patrick [mailto:epatr...@quandis.com] > Sent: Tuesday, 24 April 2012 12:45 AM > To: MooTools Users > Subject: [Moo] Re: selectbox options "selected"
> The Element.js file in MooTools core handles some attributes in a custom > manner. From a programmatic js perspective, I rarely encounter a need for > the HTML attribute. However, I _have_ encountered such a > need: when I want to reset for values to their original state. In this > case, > I use:
> This is why you don't see an HTML attribute for the 'selected' > property you are passing.
> Element.js could be modified as follows, starting @ line 561, but I'm not > sure if this would break other behavior:
> Object.append(propertySetters, {
> 'class': function (node, value) { > ('className' in node) ? node.className = value : > node.setAttribute('class', value); > },
> 'for': function (node, value) { > ('htmlFor' in node) ? node.htmlFor = value : > node.setAttribute('for', value); > },
> 'style': function (node, value) { > (node.style) ? node.style.cssText = value : > node.setAttribute('style', value); > },
> // handle 'selected' in both the javascript and HTML? > 'selected': function (node, value) { > node.selected = !!value; // not sure you really need this > if > you have the next line(s) > if (value) node.setAttribute('selected', 'selected'); > else node.removeProperties('selected'); > }
> });
> I'll defer to others regarding the wisdom of such an override.
> Eric
> On Apr 23, 9:56 am, "Steve Onnis" <st...@cfcentral.com.au> wrote: > > I know it selects it, but the actual HTML it renders i am expecting is
On Monday, April 23, 2012 9:53:08 AM UTC-4, hazlema wrote:
> You can't, obj.setProperty('selected', 'true'); will just set the value > to true.
> Best you can do is to set _selected to true then with regex you can change > _selected to selected,