Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
selectbox options "selected"
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Onnis  
View profile  
 More options Apr 23 2012, 12:16 am
From: "Steve Onnis" <st...@cfcentral.com.au>
Date: Mon, 23 Apr 2012 14:16:48 +1000
Local: Mon, Apr 23 2012 12:16 am
Subject: selectbox options "selected"

How can i get mootools to actually write the "selected" property into the
HTML when creating new <option> elements?

It seems to select the option fine but it doesn't actually write the
property to the html

Steve


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hamburger  
View profile  
 More options Apr 23 2012, 7:43 am
From: hamburger <bilidi...@web.de>
Date: Mon, 23 Apr 2012 04:43:53 -0700 (PDT)
Local: Mon, Apr 23 2012 7:43 am
Subject: Re: selectbox options "selected"
did you tried this:

                                var option = new Element('option', {
                                        'selected': true,
                                        'value': "myValue"
                                }

cheers hamburger


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Onnis  
View profile  
 More options Apr 23 2012, 7:50 am
From: "Steve Onnis" <st...@cfcentral.com.au>
Date: Mon, 23 Apr 2012 21:50:17 +1000
Local: Mon, Apr 23 2012 7:50 am
Subject: RE: [Moo] Re: selectbox options "selected"
Yup

Check this out...

http://jsfiddle.net/jgPHK/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hamburger  
View profile  
 More options Apr 23 2012, 9:09 am
From: hamburger <bilidi...@web.de>
Date: Mon, 23 Apr 2012 06:09:03 -0700 (PDT)
Local: Mon, Apr 23 2012 9:09 am
Subject: Re: selectbox options "selected"
for me it seems to work fine. (firefox 11)
option 3 is selected.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hamburger  
View profile  
 More options Apr 23 2012, 9:49 am
From: hamburger <bilidi...@web.de>
Date: Mon, 23 Apr 2012 06:49:17 -0700 (PDT)
Local: Mon, Apr 23 2012 9:49 am
Subject: Re: selectbox options "selected"
one more suggestion:
http://jsfiddle.net/jgPHK/2/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthew Hazlett  
View profile  
 More options Apr 23 2012, 9:53 am
From: Matthew Hazlett <hazl...@gmail.com>
Date: Mon, 23 Apr 2012 09:53:08 -0400
Local: Mon, Apr 23 2012 9:53 am
Subject: Re: [Moo] selectbox options "selected"

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,

I wrote this awhile back:
http://jsfiddle.net/hazlema/BwczU/

Ran into the same issue.  Thats how I delt with it.

On 4/23/2012 12:16 AM, Steve Onnis wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Onnis  
View profile  
 More options Apr 23 2012, 9:56 am
From: "Steve Onnis" <st...@cfcentral.com.au>
Date: Mon, 23 Apr 2012 23:56:26 +1000
Local: Mon, Apr 23 2012 9:56 am
Subject: RE: [Moo] Re: selectbox options "selected"
I know it selects it, but the actual HTML it renders i am expecting is

<option selected="selected" value="3">option 3</option>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Patrick  
View profile  
 More options Apr 23 2012, 10:45 am
From: Eric Patrick <epatr...@quandis.com>
Date: Mon, 23 Apr 2012 07:45:04 -0700 (PDT)
Local: Mon, Apr 23 2012 10:45 am
Subject: 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.getElements('option[selected=true]').each(function(o)
{ o.selected = true });

which requires an HTML 'selected' attribute.

You can use this:

document.id('someOptionIDTag').setAttribute('selected', 'selected');

But, that is, er, less than elegant.

The rest of my comments apply to:

https://github.com/mootools/mootools-core/blob/master/Source/Element/...

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Onnis  
View profile  
 More options Apr 23 2012, 10:49 am
From: "Steve Onnis" <st...@cfcentral.com.au>
Date: Tue, 24 Apr 2012 00:49:25 +1000
Local: Mon, Apr 23 2012 10:49 am
Subject: RE: [Moo] Re: selectbox options "selected"
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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Patrick  
View profile  
 More options Apr 23 2012, 11:19 am
From: Eric Patrick <epatr...@quandis.com>
Date: Mon, 23 Apr 2012 08:19:56 -0700 (PDT)
Local: Mon, Apr 23 2012 11:19 am
Subject: Re: [Moo] Re: selectbox options "selected"

Well, you could wrap it in a generic function, but yes, less than elegant
is definitely the rule on this.

Unless one overrides Element.js.

Eric


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Patrick  
View profile  
 More options Apr 23 2012, 11:22 am
From: Eric Patrick <epatr...@quandis.com>
Date: Mon, 23 Apr 2012 08:22:19 -0700 (PDT)
Local: Mon, Apr 23 2012 11:22 am
Subject: Re: [Moo] selectbox options "selected"

.setAttribute works; it bypasses the propertySetter overrides:

See  http://jsfiddle.net/ENqsh/

Again, not elegant :-)

Eric


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »