I''m currently using CakePHP + prototype + scriptaculous. I have a form observer on, and when the data in the form changes, I have a page that returns the html that puts a select box into a div on the page. That dropdown doesn''t get covered by the form observer though, and I need to observe that dropdown for changes in selected value. Is there an easy way to do this that I''m missing? Tracy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It sounds like you need to unregister your form observer and set it again after the form has been updated. I couldn''t tell from your description, but are you updating a div within the form that is being observed? What does your generated code look like? (I understand that you are using the Cake helpers, but I don''t know how that translates into actual HTML + JS.) Walter On Jan 31, 2008, at 2:00 PM, TracyB wrote:> > I''m currently using CakePHP + prototype + scriptaculous. I have a form > observer on, and when the data in the form changes, I have a page that > returns the html that puts a select box into a div on the page. That > dropdown doesn''t get covered by the form observer though, and I need > to observe that dropdown for changes in selected value. > > Is there an easy way to do this that I''m missing? > > Tracy >--~--~---------~--~----~------------~-------~--~----~ 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 my form code: <form id="PartAddForm" method="post" action="/cake/carts/ add"><fieldset style="display:none;"><input type="hidden" name="_method" value="POST" /></fieldset> <table> <tr> <td><div class="input"><input name="data[Cart][qty]" type="text" size="5" value="" id="CartQty" /></div></td> <td><div class="input"><input name="data[Part][part]" type="text" maxlength="20" value="" id="PartPart" /></div></td> <td><div id="require_gauge"></div></td> <td><div id="require_colour"></div></td> <td><div id="require_length"></div></td> <td><div class="input"><input name="data[Cart][mark]" type="text" value="" id="CartMark" /></div></td> <td><div class="submit"><input type="submit" value="Add Part" /></ div></td> </tr> </table> </form><script type="text/javascript"> //<![CDATA[ new Form.EventObserver(''PartAddForm'', function(element, value) {new Ajax.Updater(document.createElement(''div''),''/cake/carts/get_data'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(''PartAddForm''), requestHeaders:[''X-Update'', ''require_gauge require_colour require_length'']})}) //]]> </script> When any of the original form fields change, the Form.EventObserver fires off, and goes to the server to get html that gets dropped in the three divs in the middle of the form. The problem I''m having, is the require_colour div is partially dependent on the require_gauge div, so I need to have that field observed for changing values, once it''s on the page. I tried adding a Form.Element.EventObserver to the code that creates the require_gauge select box, but that doesn''t seem to do the trick. Tracy On Jan 31, 2:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> It sounds like you need to unregister your form observer and set it > again after the form has been updated. I couldn''t tell from your > description, but are you updating a div within the form that is being > observed? What does your generated code look like? (I understand that > you are using the Cake helpers, but I don''t know how that translates > into actual HTML + JS.) > > Walter > > On Jan 31, 2008, at 2:00 PM, TracyB wrote: > > > > > I''m currently using CakePHP + prototype + scriptaculous. I have a form > > observer on, and when the data in the form changes, I have a page that > > returns the html that puts a select box into a div on the page. That > > dropdown doesn''t get covered by the form observer though, and I need > > to observe that dropdown for changes in selected value. > > > Is there an easy way to do this that I''m missing? > > > Tracy--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmm. That''s an interesting one. I''m looking at the Form.Observer page, and it appears as though you can set an observer ticking on a form, and that it calls Form.serialize() on that form to determine if the form has changed. It''s not clear to me if Form.serialize() caches the definition of the form, and then iterates over that definition to get the individual values, or if it looks at the form again each time. It would be nice if it did the latter. I have a need for something like this, so I''m going to do a little experiment. But if anyone knows better/different, please pipe up! Walter On Jan 31, 2008, at 2:22 PM, TracyB wrote:> > This is my form code: > > <form id="PartAddForm" method="post" action="/cake/carts/ > add"><fieldset style="display:none;"><input type="hidden" > name="_method" value="POST" /></fieldset> > <table> > <tr> > <td><div class="input"><input name="data[Cart][qty]" type="text" > size="5" value="" id="CartQty" /></div></td> > <td><div class="input"><input name="data[Part][part]" type="text" > maxlength="20" value="" id="PartPart" /></div></td> > <td><div id="require_gauge"></div></td> > <td><div id="require_colour"></div></td> > <td><div id="require_length"></div></td> > <td><div class="input"><input name="data[Cart][mark]" type="text" > value="" id="CartMark" /></div></td> > <td><div class="submit"><input type="submit" value="Add Part" /></ > div></td> > </tr> > </table> > </form><script type="text/javascript"> > //<![CDATA[ > new Form.EventObserver(''PartAddForm'', function(element, value) {new > Ajax.Updater(document.createElement(''div''),''/cake/carts/get_data'', > {asynchronous:true, evalScripts:true, > parameters:Form.serialize(''PartAddForm''), requestHeaders:[''X-Update'', > ''require_gauge require_colour require_length'']})}) > //]]> > </script> > > When any of the original form fields change, the Form.EventObserver > fires off, and goes to the server to get html that gets dropped in the > three divs in the middle of the form. The problem I''m having, is the > require_colour div is partially dependent on the require_gauge div, so > I need to have that field observed for changing values, once it''s on > the page. > > I tried adding a Form.Element.EventObserver to the code that creates > the require_gauge select box, but that doesn''t seem to do the trick. > > Tracy > > On Jan 31, 2:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> It sounds like you need to unregister your form observer and set it >> again after the form has been updated. I couldn''t tell from your >> description, but are you updating a div within the form that is being >> observed? What does your generated code look like? (I understand that >> you are using the Cake helpers, but I don''t know how that translates >> into actual HTML + JS.) >> >> Walter >> >> On Jan 31, 2008, at 2:00 PM, TracyB wrote: >> >> >> >>> I''m currently using CakePHP + prototype + scriptaculous. I have a >>> form >>> observer on, and when the data in the form changes, I have a page >>> that >>> returns the html that puts a select box into a div on the page. That >>> dropdown doesn''t get covered by the form observer though, and I need >>> to observe that dropdown for changes in selected value. >> >>> Is there an easy way to do this that I''m missing? >> >>> Tracy > >--~--~---------~--~----~------------~-------~--~----~ 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, I use firebug to test and see what the value of Form.serialize is, and when the form fields are added dynamically to the page, they show up in the value every time. The only issue I''m having is how to observe the new generated form fields for changing values. On Jan 31, 2:53 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Hmm. That''s an interesting one. I''m looking at the Form.Observer > page, and it appears as though you can set an observer ticking on a > form, and that it calls Form.serialize() on that form to determine if > the form has changed. It''s not clear to me if Form.serialize() caches > the definition of the form, and then iterates over that definition to > get the individual values, or if it looks at the form again each > time. It would be nice if it did the latter. I have a need for > something like this, so I''m going to do a little experiment. > > But if anyone knows better/different, please pipe up! > > Walter > > On Jan 31, 2008, at 2:22 PM, TracyB wrote: > > > > > This is my form code: > > > <form id="PartAddForm" method="post" action="/cake/carts/ > > add"><fieldset style="display:none;"><input type="hidden" > > name="_method" value="POST" /></fieldset> > > <table> > > <tr> > > <td><div class="input"><input name="data[Cart][qty]" type="text" > > size="5" value="" id="CartQty" /></div></td> > > <td><div class="input"><input name="data[Part][part]" type="text" > > maxlength="20" value="" id="PartPart" /></div></td> > > <td><div id="require_gauge"></div></td> > > <td><div id="require_colour"></div></td> > > <td><div id="require_length"></div></td> > > <td><div class="input"><input name="data[Cart][mark]" type="text" > > value="" id="CartMark" /></div></td> > > <td><div class="submit"><input type="submit" value="Add Part" /></ > > div></td> > > </tr> > > </table> > > </form><script type="text/javascript"> > > //<![CDATA[ > > new Form.EventObserver(''PartAddForm'', function(element, value) {new > > Ajax.Updater(document.createElement(''div''),''/cake/carts/get_data'', > > {asynchronous:true, evalScripts:true, > > parameters:Form.serialize(''PartAddForm''), requestHeaders:[''X-Update'', > > ''require_gauge require_colour require_length'']})}) > > //]]> > > </script> > > > When any of the original form fields change, the Form.EventObserver > > fires off, and goes to the server to get html that gets dropped in the > > three divs in the middle of the form. The problem I''m having, is the > > require_colour div is partially dependent on the require_gauge div, so > > I need to have that field observed for changing values, once it''s on > > the page. > > > I tried adding a Form.Element.EventObserver to the code that creates > > the require_gauge select box, but that doesn''t seem to do the trick. > > > Tracy > > > On Jan 31, 2:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > >> It sounds like you need to unregister your form observer and set it > >> again after the form has been updated. I couldn''t tell from your > >> description, but are you updating a div within the form that is being > >> observed? What does your generated code look like? (I understand that > >> you are using the Cake helpers, but I don''t know how that translates > >> into actual HTML + JS.) > > >> Walter > > >> On Jan 31, 2008, at 2:00 PM, TracyB wrote: > > >>> I''m currently using CakePHP + prototype + scriptaculous. I have a > >>> form > >>> observer on, and when the data in the form changes, I have a page > >>> that > >>> returns the html that puts a select box into a div on the page. That > >>> dropdown doesn''t get covered by the form observer though, and I need > >>> to observe that dropdown for changes in selected value. > > >>> Is there an easy way to do this that I''m missing? > > >>> Tracy--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Okay, I have a working test page here, and what I have done is set the observer is on the form itself, not the individual fields. Then inside my observer''s callback, I read the value querystring and do my conditional branching from there. This callback function fires every time the form changes in any way. I am just using update to populate my fields, but I think it will work the same for your case with the Ajax calls. Just do all that inside the form observer callback. var cats = false; var dogs = false; new Form.Observer(''testform'',0.3,function(form,value){ var vars = value.toQueryParams(); if(vars && vars[''pets'']){ if(vars[''pets''] == ''Cats'' && cats == false){ $(''names'').update(''select form full of cat names here''); cats = true; dogs = false; } if(vars[''pets''] == ''Dogs'' && dogs == false){ $(''names'').update(''<select form full of dog names here''); dogs = true; cats = false; } } $(''output'').update(value); } ) There''s probably a million better ways to do this, but it works. Walter On Jan 31, 2008, at 3:12 PM, TracyB wrote:> > Well, I use firebug to test and see what the value of Form.serialize > is, and when the form fields are added dynamically to the page, they > show up in the value every time. The only issue I''m having is how to > observe the new generated form fields for changing values. > > On Jan 31, 2:53 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> Hmm. That''s an interesting one. I''m looking at the Form.Observer >> page, and it appears as though you can set an observer ticking on a >> form, and that it calls Form.serialize() on that form to determine if >> the form has changed. It''s not clear to me if Form.serialize() caches >> the definition of the form, and then iterates over that definition to >> get the individual values, or if it looks at the form again each >> time. It would be nice if it did the latter. I have a need for >> something like this, so I''m going to do a little experiment. >> >> But if anyone knows better/different, please pipe up! >> >> Walter >> >> On Jan 31, 2008, at 2:22 PM, TracyB wrote: >> >> >> >>> This is my form code: >> >>> <form id="PartAddForm" method="post" action="/cake/carts/ >>> add"><fieldset style="display:none;"><input type="hidden" >>> name="_method" value="POST" /></fieldset> >>> <table> >>> <tr> >>> <td><div class="input"><input name="data[Cart][qty]" type="text" >>> size="5" value="" id="CartQty" /></div></td> >>> <td><div class="input"><input name="data[Part][part]" type="text" >>> maxlength="20" value="" id="PartPart" /></div></td> >>> <td><div id="require_gauge"></div></td> >>> <td><div id="require_colour"></div></td> >>> <td><div id="require_length"></div></td> >>> <td><div class="input"><input name="data[Cart][mark]" type="text" >>> value="" id="CartMark" /></div></td> >>> <td><div class="submit"><input type="submit" value="Add Part" /></ >>> div></td> >>> </tr> >>> </table> >>> </form><script type="text/javascript"> >>> //<![CDATA[ >>> new Form.EventObserver(''PartAddForm'', function(element, value) {new >>> Ajax.Updater(document.createElement(''div''),''/cake/carts/get_data'', >>> {asynchronous:true, evalScripts:true, >>> parameters:Form.serialize(''PartAddForm''), requestHeaders:[''X- >>> Update'', >>> ''require_gauge require_colour require_length'']})}) >>> //]]> >>> </script> >> >>> When any of the original form fields change, the Form.EventObserver >>> fires off, and goes to the server to get html that gets dropped >>> in the >>> three divs in the middle of the form. The problem I''m having, is the >>> require_colour div is partially dependent on the require_gauge >>> div, so >>> I need to have that field observed for changing values, once it''s on >>> the page. >> >>> I tried adding a Form.Element.EventObserver to the code that creates >>> the require_gauge select box, but that doesn''t seem to do the trick. >> >>> Tracy >> >>> On Jan 31, 2:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >>>> It sounds like you need to unregister your form observer and set it >>>> again after the form has been updated. I couldn''t tell from your >>>> description, but are you updating a div within the form that is >>>> being >>>> observed? What does your generated code look like? (I understand >>>> that >>>> you are using the Cake helpers, but I don''t know how that >>>> translates >>>> into actual HTML + JS.) >> >>>> Walter >> >>>> On Jan 31, 2008, at 2:00 PM, TracyB wrote: >> >>>>> I''m currently using CakePHP + prototype + scriptaculous. I have a >>>>> form >>>>> observer on, and when the data in the form changes, I have a page >>>>> that >>>>> returns the html that puts a select box into a div on the page. >>>>> That >>>>> dropdown doesn''t get covered by the form observer though, and I >>>>> need >>>>> to observe that dropdown for changes in selected value. >> >>>>> Is there an easy way to do this that I''m missing? >> >>>>> Tracy > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you for all your help - I''ll see what I can do about figuring out how to integrate that Javascript with the form I currently have. I''m a huge newb at all this cakePHP and prototype stuff, usually I work in asp.net. If you could do me a huge favour and also show the html that goes with that javascript, i''d probably have a much easier time figuring out which bit does what :) Tracy On Jan 31, 3:47 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Okay, I have a working test page here, and what I have done is set > the observer is on the form itself, not the individual fields. Then > inside my observer''s callback, I read the value querystring and do my > conditional branching from there. This callback function fires every > time the form changes in any way. > > I am just using update to populate my fields, but I think it will > work the same for your case with the Ajax calls. Just do all that > inside the form observer callback. > > var cats = false; > var dogs = false; > new Form.Observer(''testform'',0.3,function(form,value){ > var vars = value.toQueryParams(); > if(vars && vars[''pets'']){ > if(vars[''pets''] == ''Cats'' && cats == false){ > $(''names'').update(''select form full of cat names here''); > cats = true; > dogs = false; > } > if(vars[''pets''] == ''Dogs'' && dogs == false){ > $(''names'').update(''<select form full of dog names here''); > dogs = true; > cats = false; > } > } > $(''output'').update(value); > } > ) > > There''s probably a million better ways to do this, but it works. > > Walter > > On Jan 31, 2008, at 3:12 PM, TracyB wrote: > > > > > Well, I use firebug to test and see what the value of Form.serialize > > is, and when the form fields are added dynamically to the page, they > > show up in the value every time. The only issue I''m having is how to > > observe the new generated form fields for changing values. > > > On Jan 31, 2:53 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > >> Hmm. That''s an interesting one. I''m looking at the Form.Observer > >> page, and it appears as though you can set an observer ticking on a > >> form, and that it calls Form.serialize() on that form to determine if > >> the form has changed. It''s not clear to me if Form.serialize() caches > >> the definition of the form, and then iterates over that definition to > >> get the individual values, or if it looks at the form again each > >> time. It would be nice if it did the latter. I have a need for > >> something like this, so I''m going to do a little experiment. > > >> But if anyone knows better/different, please pipe up! > > >> Walter > > >> On Jan 31, 2008, at 2:22 PM, TracyB wrote: > > >>> This is my form code: > > >>> <form id="PartAddForm" method="post" action="/cake/carts/ > >>> add"><fieldset style="display:none;"><input type="hidden" > >>> name="_method" value="POST" /></fieldset> > >>> <table> > >>> <tr> > >>> <td><div class="input"><input name="data[Cart][qty]" type="text" > >>> size="5" value="" id="CartQty" /></div></td> > >>> <td><div class="input"><input name="data[Part][part]" type="text" > >>> maxlength="20" value="" id="PartPart" /></div></td> > >>> <td><div id="require_gauge"></div></td> > >>> <td><div id="require_colour"></div></td> > >>> <td><div id="require_length"></div></td> > >>> <td><div class="input"><input name="data[Cart][mark]" type="text" > >>> value="" id="CartMark" /></div></td> > >>> <td><div class="submit"><input type="submit" value="Add Part" /></ > >>> div></td> > >>> </tr> > >>> </table> > >>> </form><script type="text/javascript"> > >>> //<![CDATA[ > >>> new Form.EventObserver(''PartAddForm'', function(element, value) {new > >>> Ajax.Updater(document.createElement(''div''),''/cake/carts/get_data'', > >>> {asynchronous:true, evalScripts:true, > >>> parameters:Form.serialize(''PartAddForm''), requestHeaders:[''X- > >>> Update'', > >>> ''require_gauge require_colour require_length'']})}) > >>> //]]> > >>> </script> > > >>> When any of the original form fields change, the Form.EventObserver > >>> fires off, and goes to the server to get html that gets dropped > >>> in the > >>> three divs in the middle of the form. The problem I''m having, is the > >>> require_colour div is partially dependent on the require_gauge > >>> div, so > >>> I need to have that field observed for changing values, once it''s on > >>> the page. > > >>> I tried adding a Form.Element.EventObserver to the code that creates > >>> the require_gauge select box, but that doesn''t seem to do the trick. > > >>> Tracy > > >>> On Jan 31, 2:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > >>>> It sounds like you need to unregister your form observer and set it > >>>> again after the form has been updated. I couldn''t tell from your > >>>> description, but are you updating a div within the form that is > >>>> being > >>>> observed? What does your generated code look like? (I understand > >>>> that > >>>> you are using the Cake helpers, but I don''t know how that > >>>> translates > >>>> into actual HTML + JS.) > > >>>> Walter > > >>>> On Jan 31, 2008, at 2:00 PM, TracyB wrote: > > >>>>> I''m currently using CakePHP + prototype + scriptaculous. I have a > >>>>> form > >>>>> observer on, and when the data in the form changes, I have a page > >>>>> that > >>>>> returns the html that puts a select box into a div on the page. > >>>>> That > >>>>> dropdown doesn''t get covered by the form observer though, and I > >>>>> need > >>>>> to observe that dropdown for changes in selected value. > > >>>>> Is there an easy way to do this that I''m missing? > > >>>>> Tracy--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Never mind! I got it to work thanks so much. I think the problem is that the cakephp ajaxhelper was creating a Form.EventObserver, rather than the Form.Observer. Thanks again, I never would''ve figured that out on my own. Tracy On Jan 31, 4:03 pm, TracyB <html.hu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you for all your help - I''ll see what I can do about figuring > out how to integrate that Javascript with the form I currently have. > I''m a huge newb at all this cakePHP and prototype stuff, usually I > work in asp.net. > > If you could do me a huge favour and also show the html that goes with > that javascript, i''d probably have a much easier time figuring out > which bit does what :) > > Tracy > > On Jan 31, 3:47 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > > Okay, I have a working test page here, and what I have done is set > > the observer is on the form itself, not the individual fields. Then > > inside my observer''s callback, I read the value querystring and do my > > conditional branching from there. This callback function fires every > > time the form changes in any way. > > > I am just using update to populate my fields, but I think it will > > work the same for your case with the Ajax calls. Just do all that > > inside the form observer callback. > > > var cats = false; > > var dogs = false; > > new Form.Observer(''testform'',0.3,function(form,value){ > > var vars = value.toQueryParams(); > > if(vars && vars[''pets'']){ > > if(vars[''pets''] == ''Cats'' && cats == false){ > > $(''names'').update(''select form full of cat names here''); > > cats = true; > > dogs = false; > > } > > if(vars[''pets''] == ''Dogs'' && dogs == false){ > > $(''names'').update(''<select form full of dog names here''); > > dogs = true; > > cats = false; > > } > > } > > $(''output'').update(value); > > } > > ) > > > There''s probably a million better ways to do this, but it works. > > > Walter > > > On Jan 31, 2008, at 3:12 PM, TracyB wrote: > > > > Well, I use firebug to test and see what the value of Form.serialize > > > is, and when the form fields are added dynamically to the page, they > > > show up in the value every time. The only issue I''m having is how to > > > observe the new generated form fields for changing values. > > > > On Jan 31, 2:53 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > >> Hmm. That''s an interesting one. I''m looking at the Form.Observer > > >> page, and it appears as though you can set an observer ticking on a > > >> form, and that it calls Form.serialize() on that form to determine if > > >> the form has changed. It''s not clear to me if Form.serialize() caches > > >> the definition of the form, and then iterates over that definition to > > >> get the individual values, or if it looks at the form again each > > >> time. It would be nice if it did the latter. I have a need for > > >> something like this, so I''m going to do a little experiment. > > > >> But if anyone knows better/different, please pipe up! > > > >> Walter > > > >> On Jan 31, 2008, at 2:22 PM, TracyB wrote: > > > >>> This is my form code: > > > >>> <form id="PartAddForm" method="post" action="/cake/carts/ > > >>> add"><fieldset style="display:none;"><input type="hidden" > > >>> name="_method" value="POST" /></fieldset> > > >>> <table> > > >>> <tr> > > >>> <td><div class="input"><input name="data[Cart][qty]" type="text" > > >>> size="5" value="" id="CartQty" /></div></td> > > >>> <td><div class="input"><input name="data[Part][part]" type="text" > > >>> maxlength="20" value="" id="PartPart" /></div></td> > > >>> <td><div id="require_gauge"></div></td> > > >>> <td><div id="require_colour"></div></td> > > >>> <td><div id="require_length"></div></td> > > >>> <td><div class="input"><input name="data[Cart][mark]" type="text" > > >>> value="" id="CartMark" /></div></td> > > >>> <td><div class="submit"><input type="submit" value="Add Part" /></ > > >>> div></td> > > >>> </tr> > > >>> </table> > > >>> </form><script type="text/javascript"> > > >>> //<![CDATA[ > > >>> new Form.EventObserver(''PartAddForm'', function(element, value) {new > > >>> Ajax.Updater(document.createElement(''div''),''/cake/carts/get_data'', > > >>> {asynchronous:true, evalScripts:true, > > >>> parameters:Form.serialize(''PartAddForm''), requestHeaders:[''X- > > >>> Update'', > > >>> ''require_gauge require_colour require_length'']})}) > > >>> //]]> > > >>> </script> > > > >>> When any of the original form fields change, the Form.EventObserver > > >>> fires off, and goes to the server to get html that gets dropped > > >>> in the > > >>> three divs in the middle of the form. The problem I''m having, is the > > >>> require_colour div is partially dependent on the require_gauge > > >>> div, so > > >>> I need to have that field observed for changing values, once it''s on > > >>> the page. > > > >>> I tried adding a Form.Element.EventObserver to the code that creates > > >>> the require_gauge select box, but that doesn''t seem to do the trick. > > > >>> Tracy > > > >>> On Jan 31, 2:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > >>>> It sounds like you need to unregister your form observer and set it > > >>>> again after the form has been updated. I couldn''t tell from your > > >>>> description, but are you updating a div within the form that is > > >>>> being > > >>>> observed? What does your generated code look like? (I understand > > >>>> that > > >>>> you are using the Cake helpers, but I don''t know how that > > >>>> translates > > >>>> into actual HTML + JS.) > > > >>>> Walter > > > >>>> On Jan 31, 2008, at 2:00 PM, TracyB wrote: > > > >>>>> I''m currently using CakePHP + prototype + scriptaculous. I have a > > >>>>> form > > >>>>> observer on, and when the data in the form changes, I have a page > > >>>>> that > > >>>>> returns the html that puts a select box into a div on the page. > > >>>>> That > > >>>>> dropdown doesn''t get covered by the form observer though, and I > > >>>>> need > > >>>>> to observe that dropdown for changes in selected value. > > > >>>>> Is there an easy way to do this that I''m missing? > > > >>>>> Tracy--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---