Form.Observer does not appear to correctly report when a checkbox ha been updated. if i am monitoring a form, and i check the box, it registers, but then if i uncheck it it doesn''t send a second trigger. --~--~---------~--~----~------------~-------~--~----~ 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''m not sure if it''s related, but in IE you have to click somewhere else on the page to trigger onchange for checkboxes. Does Form.Observer register a change when you click somewhere else on the page? -Hector louis w wrote:> Form.Observer does not appear to correctly report when a checkbox ha > been updated. > > if i am monitoring a form, and i check the box, it registers, but then > if i uncheck it it doesn''t send a second trigger. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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''m not sure if it''s related, but in IE you have to click somewhere else > on the page to trigger onchange for checkboxes.That''s a good point. If you watch the ''click'' event, though, you''re okay (rather than ''change''). Have to deal with the double-click thing, too, with IE (the first click will ''click'', the second if it''s fast enough will ''dblclick''). -- T.J. Crowder tj / crowder software / com On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m not sure if it''s related, but in IE you have to click somewhere else > on the page to trigger onchange for checkboxes. Does Form.Observer > register a change when you click somewhere else on the page? > > -Hector > > louis w wrote: > > Form.Observer does not appear to correctly report when a checkbox ha > > been updated. > > > if i am monitoring a form, and i check the box, it registers, but then > > if i uncheck it it doesn''t send a second trigger. > >--~--~---------~--~----~------------~-------~--~----~ 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''m in Firefox. Even tried clicking outside and back it. It seems to only register the first time you click it. On Jun 19, 2:01 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote:> > I''m not sure if it''s related, but in IE you have to click somewhere else > > on the page to trigger onchange for checkboxes. > > That''s a good point. If you watch the ''click'' event, though, you''re > okay (rather than ''change''). Have to deal with the double-click > thing, too, with IE (the first click will ''click'', the second if it''s > fast enough will ''dblclick''). > -- > T.J. Crowder > tj / crowder software / com > > On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > on the page to trigger onchange for checkboxes. Does Form.Observer > > register a change when you click somewhere else on the page? > > > -Hector > > > louis w wrote: > > > Form.Observer does not appear to correctly report when a checkbox ha > > > been updated. > > > > if i am monitoring a form, and i check the box, it registers, but then > > > if i uncheck it it doesn''t send a second trigger.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Both Hector and I seem to have missed the minor detail that you said you were using Form.Observer. :-) A quick-and-dirty check works for me. Are you sure the checkbox has a name attribute? That''s important, because the change detection is based on Form.serialize(). But if it were that, I would expect you to get *no* change notifications, not one. Try creating a pared-down test case and posting it; usually creating it shows you what''s wrong, but if not then you can post it and maybe one of us''ll see it. -- T.J. Crowder tj / crowder software / com On Jun 19, 7:09 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m in Firefox. Even tried clicking outside and back it. It seems to > only register the first time you click it. > > On Jun 19, 2:01 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > on the page to trigger onchange for checkboxes. > > > That''s a good point. If you watch the ''click'' event, though, you''re > > okay (rather than ''change''). Have to deal with the double-click > > thing, too, with IE (the first click will ''click'', the second if it''s > > fast enough will ''dblclick''). > > -- > > T.J. Crowder > > tj / crowder software / com > > > On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > on the page to trigger onchange for checkboxes. Does Form.Observer > > > register a change when you click somewhere else on the page? > > > > -Hector > > > > louis w wrote: > > > > Form.Observer does not appear to correctly report when a checkbox ha > > > > been updated. > > > > > if i am monitoring a form, and i check the box, it registers, but then > > > > if i uncheck it it doesn''t send a second trigger. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try this out. http://pastebin.com/m66282c9d It includes a patch by kangax to include the element in the call back:: http://prototype.lighthouseapp.com/attachments/26787/0001-Form.Observer-to-pass-changed-element-to-a-callback.patch On Jun 19, 4:25 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote:> Both Hector and I seem to have missed the minor detail that you said > you were using Form.Observer. :-) > > A quick-and-dirty check works for me. Are you sure the checkbox has a > name attribute? That''s important, because the change detection is > based on Form.serialize(). But if it were that, I would expect you to > get *no* change notifications, not one. > > Try creating a pared-down test case and posting it; usually creating > it shows you what''s wrong, but if not then you can post it and maybe > one of us''ll see it. > -- > T.J. Crowder > tj / crowder software / com > > On Jun 19, 7:09 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m in Firefox. Even tried clicking outside and back it. It seems to > > only register the first time you click it. > > > On Jun 19, 2:01 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > on the page to trigger onchange for checkboxes. > > > > That''s a good point. If you watch the ''click'' event, though, you''re > > > okay (rather than ''change''). Have to deal with the double-click > > > thing, too, with IE (the first click will ''click'', the second if it''s > > > fast enough will ''dblclick''). > > > -- > > > T.J. Crowder > > > tj / crowder software / com > > > > On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > on the page to trigger onchange for checkboxes. Does Form.Observer > > > > register a change when you click somewhere else on the page? > > > > > -Hector > > > > > louis w wrote: > > > > > Form.Observer does not appear to correctly report when a checkbox ha > > > > > been updated. > > > > > > if i am monitoring a form, and i check the box, it registers, but then > > > > > if i uncheck it it doesn''t send a second trigger.--~--~---------~--~----~------------~-------~--~----~ 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 can''t reproduce this as well. Using FF3 (os x 10.5.3) everything works as expected. A failing test case would be helpful. - kangax On Jun 19, 4:58 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try this out. > > http://pastebin.com/m66282c9d > > It includes a patch by kangax to include the element in the call > back::http://prototype.lighthouseapp.com/attachments/26787/0001-Form.Observ... > > On Jun 19, 4:25 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > Both Hector and I seem to have missed the minor detail that you said > > you were using Form.Observer. :-) > > > A quick-and-dirty check works for me. Are you sure the checkbox has a > > name attribute? That''s important, because the change detection is > > based on Form.serialize(). But if it were that, I would expect you to > > get *no* change notifications, not one. > > > Try creating a pared-down test case and posting it; usually creating > > it shows you what''s wrong, but if not then you can post it and maybe > > one of us''ll see it. > > -- > > T.J. Crowder > > tj / crowder software / com > > > On Jun 19, 7:09 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''m in Firefox. Even tried clicking outside and back it. It seems to > > > only register the first time you click it. > > > > On Jun 19, 2:01 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > > on the page to trigger onchange for checkboxes. > > > > > That''s a good point. If you watch the ''click'' event, though, you''re > > > > okay (rather than ''change''). Have to deal with the double-click > > > > thing, too, with IE (the first click will ''click'', the second if it''s > > > > fast enough will ''dblclick''). > > > > -- > > > > T.J. Crowder > > > > tj / crowder software / com > > > > > On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > > on the page to trigger onchange for checkboxes. Does Form.Observer > > > > > register a change when you click somewhere else on the page? > > > > > > -Hector > > > > > > louis w wrote: > > > > > > Form.Observer does not appear to correctly report when a checkbox ha > > > > > > been updated. > > > > > > > if i am monitoring a form, and i check the box, it registers, but then > > > > > > if i uncheck it it doesn''t send a second trigger.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kangax, the code I supplied in pastebin worked for you? everytime you check/uncheck the checkbox it displays it in the console? On Jun 19, 5:24 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I can''t reproduce this as well. Using FF3 (os x 10.5.3) everything > works as expected. A failing test case would be helpful. > > - kangax > > On Jun 19, 4:58 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Try this out. > > >http://pastebin.com/m66282c9d > > > It includes a patch by kangax to include the element in the call > > back::http://prototype.lighthouseapp.com/attachments/26787/0001-Form.Observ... > > > On Jun 19, 4:25 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > Both Hector and I seem to have missed the minor detail that you said > > > you were using Form.Observer. :-) > > > > A quick-and-dirty check works for me. Are you sure the checkbox has a > > > name attribute? That''s important, because the change detection is > > > based on Form.serialize(). But if it were that, I would expect you to > > > get *no* change notifications, not one. > > > > Try creating a pared-down test case and posting it; usually creating > > > it shows you what''s wrong, but if not then you can post it and maybe > > > one of us''ll see it. > > > -- > > > T.J. Crowder > > > tj / crowder software / com > > > > On Jun 19, 7:09 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m in Firefox. Even tried clicking outside and back it. It seems to > > > > only register the first time you click it. > > > > > On Jun 19, 2:01 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > > > on the page to trigger onchange for checkboxes. > > > > > > That''s a good point. If you watch the ''click'' event, though, you''re > > > > > okay (rather than ''change''). Have to deal with the double-click > > > > > thing, too, with IE (the first click will ''click'', the second if it''s > > > > > fast enough will ''dblclick''). > > > > > -- > > > > > T.J. Crowder > > > > > tj / crowder software / com > > > > > > On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > > > on the page to trigger onchange for checkboxes. Does Form.Observer > > > > > > register a change when you click somewhere else on the page? > > > > > > > -Hector > > > > > > > louis w wrote: > > > > > > > Form.Observer does not appear to correctly report when a checkbox ha > > > > > > > been updated. > > > > > > > > if i am monitoring a form, and i check the box, it registers, but then > > > > > > > if i uncheck it it doesn''t send a second trigger.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is more problematic than I have expected. The reason why it doesn''t work is because plain comparison (==) has little effect when operands are arrays : ) I came up with a replacement but it''s far from the best solution and doesn''t detect changed elements reliably (i.e. always returns first element from the group of same-named ones). This is probably a good candidate for a separate class, based on Abstract.TimedObserver. The idea is to associate element with serialized value when storing form "state". This way, it would be MUCH easier to properly detect all changed elements, passing them to a callback. I''ll take a look at it later. Best, kangax /* another try */ Form.Observer = Class.create(Abstract.TimedObserver, { getValue: function() { return Form.serialize(this.element, true); }, execute: function() { var value = this.getValue(); var changedElements = []; for (var prop in value) { var valueProxy = { }, lastValueProxy = { }; valueProxy[prop] = value[prop]; lastValueProxy[prop] = this.lastValue[prop]; if (Object.toQueryString(valueProxy) !=Object.toQueryString(lastValueProxy)) { console.log(prop); changedElements.push(this.element.down(''[name="''+ prop +''"]'')); } } if (changedElements.length > 0) { this.callback(this.element, Object.toQueryString(value), changedElements); this.lastValue = value; } } }); new Form.Observer(''someForm'', 0.3, function() { console.log(arguments); }); On Jun 19, 5:28 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> kangax, the code I supplied in pastebin worked for you? everytime you > check/uncheck the checkbox it displays it in the console? > > On Jun 19, 5:24 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I can''t reproduce this as well. Using FF3 (os x 10.5.3) everything > > works as expected. A failing test case would be helpful. > > > - kangax > > > On Jun 19, 4:58 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Try this out. > > > >http://pastebin.com/m66282c9d > > > > It includes a patch by kangax to include the element in the call > > > back::http://prototype.lighthouseapp.com/attachments/26787/0001-Form.Observ... > > > > On Jun 19, 4:25 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > > Both Hector and I seem to have missed the minor detail that you said > > > > you were using Form.Observer. :-) > > > > > A quick-and-dirty check works for me. Are you sure the checkbox has a > > > > name attribute? That''s important, because the change detection is > > > > based on Form.serialize(). But if it were that, I would expect you to > > > > get *no* change notifications, not one. > > > > > Try creating a pared-down test case and posting it; usually creating > > > > it shows you what''s wrong, but if not then you can post it and maybe > > > > one of us''ll see it. > > > > -- > > > > T.J. Crowder > > > > tj / crowder software / com > > > > > On Jun 19, 7:09 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I''m in Firefox. Even tried clicking outside and back it. It seems to > > > > > only register the first time you click it. > > > > > > On Jun 19, 2:01 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote: > > > > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > > > > on the page to trigger onchange for checkboxes. > > > > > > > That''s a good point. If you watch the ''click'' event, though, you''re > > > > > > okay (rather than ''change''). Have to deal with the double-click > > > > > > thing, too, with IE (the first click will ''click'', the second if it''s > > > > > > fast enough will ''dblclick''). > > > > > > -- > > > > > > T.J. Crowder > > > > > > tj / crowder software / com > > > > > > > On Jun 19, 6:30 pm, Hector Virgen <djvir...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > I''m not sure if it''s related, but in IE you have to click somewhere else > > > > > > > on the page to trigger onchange for checkboxes. Does Form.Observer > > > > > > > register a change when you click somewhere else on the page? > > > > > > > > -Hector > > > > > > > > louis w wrote: > > > > > > > > Form.Observer does not appear to correctly report when a checkbox ha > > > > > > > > been updated. > > > > > > > > > if i am monitoring a form, and i check the box, it registers, but then > > > > > > > > if i uncheck it it doesn''t send a second trigger.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---