Setting The Value Of Hidden Field From Value In Separate Table
Setting The Value Of Hidden Field From Value In Separate Table
I have two DataTables and two Editors. One table is a parent and one contains child records. The child table is synchronized with the parent (thanks Crush123 and Alan) and everything works fine except when I want to create a new child record.
The underlying database has a foreign key restraint to be sure that a child is associated with a parent.
My problem is, when creating a new child, how do I populate the (hidden) foreign key in the child with the primary key of the selected parent?
I can, and do get the primary key with an on-click event in the parent, but I can't see how to set the child field to that variable. Nor do I see how to pass that back to the server so that I can assign it in PHP.
Frank
Replies
Use the
val()
method to set the field value :-)Allan
Thanks, but I think I wasn't clear enough.
This applies only when Table B (child) TableTools button "New" is selected.
At that point I need to automatically set the value of the child foreign key to that of the parent's primary key.
I can get the value I need in this parent's function
But how do I access either the child datatable or child editor from here - the parent - in order to set the value in the child?
Or is this the wrong place? Should I attach the code to an event in either the child datatable or Editor when "New" is selected?
If so, the same problem arises - When I'm in table/editor B, how do I get a value from a specific column in the currently selected row in table A?
Frank
I presume you have access to the child Editor instance so you can use its API? If so, perhaps the best way would be to set the default value for that field in your function above -
field().def()
will let you set a default, and that will be used oncreate
.Allan
Thanks, Allan. That worked great!
Frank