Can someone please let me know how to get consistent values from: var w = $(myElement).readAttribute("disabled"); I am getting : null, " ", "disabled" depending on IE or FF. I thought Prototype (1.6) was supposed to fix this ? Thanks, Crash. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I have run into an issue similar to this, where a page loads with a value set inside the elements markup, then JS later modified the obj.value property, when the value property was read again by using getAttribute it wasn''t what the JS had set it to, it can be very tricky at times. Based on what you''ve written, I would assume FF allows you to set the disabled property w/o a value, where as IE is forcing it to say "disabled = disabled" and then the third case is where it is not set, where you get NULL. So with that in mind you could write an easy enough conditional to get by w/o having a whitelist of values to accept. if(ele.readAttribute("disabled")) doSomething(); http://prototypejs.org/api/element#method-readattribute On May 5, 9:21 am, crashmeister <google2...-ZFRd4CDXLT5Wk0Htik3J/w@public.gmane.org> wrote:> Can someone please let me know how to get consistent values from: > > var w = $(myElement).readAttribute("disabled"); > > I am getting : null, " ", "disabled" depending on IE or FF. > > I thought Prototype (1.6) was supposed to fix this ? > > Thanks, > Crash.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 5, 11:21 pm, crashmeister <google2...-ZFRd4CDXLT5Wk0Htik3J/w@public.gmane.org> wrote:> Can someone please let me know how to get consistent values from: > > var w = $(myElement).readAttribute("disabled"); > > I am getting : null, " ", "disabled" depending on IE or FF.Use: var w = myElement.disabled; or if you want to guarantee a boolean: var w = !!myElement.disabled; -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I have patched Prototype to give the desired consistent result of "disabled". http://github.com/jdalton/prototype/commit/040453f86e0d6f4b9dbdc03732e3e33b63b2a385 - JDD --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 7, 2:43 pm, jdalton <John.David.Dal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have patched Prototype to give the desired consistent result of > "disabled".I didn''t request that, nor do I consider it the desired result. The disabled attribute is a boolean, therefore any function that returns its value should also return a boolean. All that is required is to get the value of the DOM element''s disabled property directly and if the result is anything other than boolean true, return false. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Well in that case I am simply enforcing what Prototype thinks it should be, which it considers it a flag -> the name of the attribute so .disabled == "disabled", .readonly == "readonly" .multiple == "multiple" Part 2 of the patch: http://github.com/jdalton/prototype/commit/d062091cece88413a249ffe086fe416c1b324d04 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Element#readAttribute is meant to work the way the native Element#getAttribute _ought_ to. The DOM spec says getAttribute should always return the string value of the attribute. IE(<= 7) incorrectly maps HTML attributes to DOM properties, such that node.getAttribute(''disabled'') === node.disabled. In other words: if you want the boolean, you''ve already got the JS property. Element#readAttribute aims for the consistent behavior across browsers that getAttribute lacks. Cheers, Andrew On May 7, 3:45 am, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On May 7, 2:43 pm, jdalton <John.David.Dal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have patched Prototype to give the desired consistent result of > > "disabled". > > I didn''t request that, nor do I consider it the desired result. > > The disabled attribute is a boolean, therefore any function that > returns its value should also return a boolean. All that is required > is to get the value of the DOM element''s disabled property directly > and if the result is anything other than boolean true, return false. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 8, 12:52 am, Andrew Dupont <goo...-TiabPMV39B5K4mp1Ns0Z8Q@public.gmane.org> wrote:> Element#readAttribute is meant to work the way the native > Element#getAttribute _ought_ to.The term "native" does not help me here: when you say "ought to", are you referring to the DOM 2 Core specification or the actual behaviour in various implementations?> The DOM spec says getAttribute should > always return the string value of the attribute.Which infers (to me) that getAttribute(''disabled'') should return "true" if the disabled attribute is present in the markup and "null" if it isn''t. If it has been set by script, it should return "true" or "false". When setting the value in the markup, there are differences in browsers. Firefox seems to think HTML should be treated as XML - getAttribute returns ''disabled'' only if the attribute is set using disabled="disabled", but results in the bizare situation where setting disabled="enabled" (or "false" any value you like) disables the control but getAttribute returns the literal value (i.e. "enabled" or "false" or whatever).> IE(<= 7) incorrectly > maps HTML attributes to DOM properties, such that > node.getAttribute(''disabled'') === node.disabled.It is incorrect in that getAttribute returns a boolean instead of a string, however that is no worse that Firefox, which returns the null object (converts to an empty string) even if the attribute is present. The HTML specification doesn''t provide a value for the disabled attribute, it just says what the behaviour is if it is present. The DOM HTML specification says that the value should be true or false.> In other words: if you want the boolean, you''ve already got the JS > property.Which was my point. Reading the property directly is at least consistent in a wide variety of browsers, does not require any additional code and can be used directly in conditional statements: if (el.disabled) {...} seems much clearer to me (and much less prone to error) than: if (el.readAttribute(''disabled'') === ''disabled'') {...}> Element#readAttribute aims for the consistent behavior > across browsers that getAttribute lacks.Some may infer that consistency means returning values like "enabled", "unchecked" and so on. Have you considered including the selected attribute in the list of those supported by readAttribute?. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 7, 10:10 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On May 8, 12:52 am, Andrew Dupont <goo...-TiabPMV39B5K4mp1Ns0Z8Q@public.gmane.org> wrote: > > > Element#readAttribute is meant to work the way the native > > Element#getAttribute _ought_ to. > > The term "native" does not help me here: when you say "ought to", are > you referring to the DOM 2 Core specification or the actual behaviour > in various implementations?I am referring to the spec. Element#readAttribute implements the spec''s definition of Element#getAttribute.> > > The DOM spec says getAttribute should > > always return the string value of the attribute. > > Which infers (to me) that getAttribute(''disabled'') should return > "true" if the disabled attribute is present in the markup and "null" > if it isn''t. If it has been set by script, it should return "true" or > "false".No, it should return "disabled" if the disabled attribute is present and set to "disabled". Otherwise it should return "". You''ve got Element#hasAttribute if you want to check for the attribute''s presence altogether. (This is a drawback of the prescribed behavior, by the way — there''s no way to distinguish between "<input disabled="" />" and "<input>" (attribute not present vs. attribute explicitly set to the empty string).) We''re following the XHTML behavior here, not HTML, because the former is a sane subset of the latter.> When setting the value in the markup, there are differences in > browsers. Firefox seems to think HTML should be treated as XML - > getAttribute returns ''disabled'' only if the attribute is set using > disabled="disabled", but results in the bizare situation where setting > disabled="enabled" (or "false" any value you like) disables the > control but getAttribute returns the literal value (i.e. "enabled" or > "false" or whatever).Yeah, that''s crazy and stupid and a browser bug.> [snip] > > Reading the property directly is at least > consistent in a wide variety of browsers, does not require any > additional code and can be used directly in conditional statements: > > if (el.disabled) {...} > > seems much clearer to me (and much less prone to error) than: > > if (el.readAttribute(''disabled'') === ''disabled'') {...} >I agree completely. The former is better. This is an edge case, but it''s worth fixing anyway.> > Element#readAttribute aims for the consistent behavior > > across browsers that getAttribute lacks. > > Some may infer that consistency means returning values like "enabled", > "unchecked" and so on. > > Have you considered including the selected attribute in the list of > those supported by readAttribute?.I haven''t, but this isn''t my area of expertise. Care to do some research for us? ;-) Cheers, Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---