Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Synchronizing Parent-Child IDs when using HasManyComplexTableField


Go to End


2 Posts   1115 Views

Avatar
ScottT

Community Member, 9 Posts

10 May 2012 at 11:28am

Hello,
I need some assistance with using a HasManyComplexTableField on a basic form. I have a tabbed form that holds information about a client. The client has many addresses. I am using a HasManyComplexTableField to enter addresses that belong to the client. For the life of us, my coding partner and I have not be able to figure out how to accomplish this.

The main problem is that when an address is saved, I would like the ClientID to be written to the Address table. I have tried many different ways to set the ClientID manually in the Addresses popup form. For example, I have used fieldset->push() to add it as a hidden field to the fieldset passed to the HasManyCTF to set appropriate ClientID that way. However, the value is often not preserved in the generated Addresses form.

The form itself subclasses Page. If I create a has_one relationship to Client and a has_many to Addresses, I do get a drop down list in Addresses which allows me to select the right client. However, this is a front-end form and I would like the correct client to be automatically selected. The client that should automatically be associated with the Address HasManyCTF is evidently the one then loaded into the parent form.

If have also tried using the replaceWith method on the FieldSet object to replace the DropDown ClientID field with a hidden one. However, the value comes through as empty which results in the address being saved with a ClientID of 0.

Can anyone suggest a way to have the parent and child HasManyCTF synchronized so that when the HasMany is saved it automatically writes the correct ClientID without this having to be set by the user then entering the data?

This seems like a pretty ordinary use case so I think there must be something very basic I am missing.

Happy to post code excerpts if this will help.

Thanks in advance for your help. Have been stumped by this for several days now.

Avatar
ScottT

Community Member, 9 Posts

11 May 2012 at 7:30am

**BUMP**

Anyone reading this forum who knows about HasManyCTF???