I'm working on a view to add a record to a table.
The table (or model) has a field and this field belongsTo another
model.
In the second model there's another field and, depending on the value
of this field, I want to show or hide some element in the
aforementioned view.

E.g.:
table1 >>> model1
id
name
table2_id
optional_field1
optional_field2

table2 >>> model2
id
flag

When I'm in the "add" view of model1 and I select a value for
table2_id I want to query table2, check the value of flag and show or
hide optional_field1 and optional_field2 if flag is true or false.

I tried to solve this in 2 ways but none works.
1st method:
In the add view of Model1 I put:
                $options = array('url' => 'update_div','update' =>
'someid');
                echo $ajax->observeField('model1table2id',$options);

In the view I don't put
$form->input('optional_field1');
$form->input('optional_field2');

In the controller I put an update_div action that checks model2->flag
and I created a view "update_div" that echoes
$form->input('optional_field1');
$form->input('optional_field2');

This approch works, sort of but, when I save, optional_field1 and
optional_field2 aren't saved, the format of the array $this->data in
the controller is wrong for the optional fields. :-(

2nd method:
In the add view
                $remoteFunction = $ajax->remoteFunction(
                        array(
                                'url' => 'update_div',
                                'with' => 
'Form.Element.serialize("model1table2id")'
                        )
                );
                echo $form->input('table2_id', array('onchange' =>
$remoteFunction));

In the view I put
$form->input('optional_field1');
$form->input('optional_field2');

The controller action "update_div" is the same as in the 1st example.
In the update_div.ctp file I tried to put some javascript to hide or
show the div that contains the optional fields but the script isn't
executed.

Can you please help me and suggest me the right way to accomplish
this?

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to