"You're doing it wrong" (c) If you fill some field based on other field value, do it in controller if you already have 1st field value. That's all.
On Oct 12, 4:59 pm, emmexx <[email protected]> wrote: > On 11 Ott, 06:55, "Dr. Loboto" <[email protected]> wrote: > > > Three ways: > > 1. Re-run your JS. > > 2. Do same logic when output form. > > 3. When show/hide fields by JS, keep form state in some hidden field > > (s) and show/hide when output form based on its value(s). > > I tried to use your suggestions and found many other problems... :-( > > I have an "add" view with 2 select boxes. > > Changes in the 1st select are "observed" by an ajax->observeField that > fires a function in the controller and fills the option part of the > second select (e.g. 1st select lists countries and second select lists > regions of the selected country). > > This works when the view loads the 1st time. > > If there's a validation error the 1st select is ok but the 2nd one is > not updated. This is ok, when cake reloads the form the 2nd select > option list is empty. > So I tried to start the observedField function by changing the > selected option in the 1st select using javascript and the load event. > Javascript changes the select value But the observeField routine > doesn't start. > Moreover if I try to change manually (not in code) the select value > the observeField function starts only the second time I select a > value, not the 1st one. > > This is the relevant code of my add.ctp view: > > $options = array('url' => 'update_select','update' => > 'Model1Model3Id','type' => 'synchronous'); > echo $ajax->observeField('Model1Model2Id',$options); > > echo $javascript->codeBlock('function updateonReload() > { > var x= > document.getElementById("Model1Model2Id"); > //alert(x.selectedIndex); > var tmp=x.selectedIndex; > //x.selectedIndex=0; > x.selectedIndex=tmp; > }'); > > echo $javascript->event('window','load','updateonReload()'); > > I'm a little bit lost... > > Thank you > maxx --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
