Best way to create a child while creating a parent
Best way to create a child while creating a parent
I'm looking at this example. I want to recreate it with an additional feature.
Current behaviour:
- Click "new" to create a new site.
- In the form that pops up, type the site name as, e.g., "NewSite".
- Click "new" in that form to add a new user.
- Fill in the user info e.g. "User Bob". Note: You can't select any site for this new user.
- If you click "create", it returns you to the form where you've started defining "NewSite", but no users, including User Bob, are there.
- User Bob seems to have disappeared because it isn't associated with any site.
I understand this is because NewSite hasn't been committed to the database at the point you're creating User Bob. Is there a recommended way to do this (i.e. create a child concurrent with creating the parent) either in the front end or the node backend?
Answers
At the moment no - however, it is a very good point. Let me think on this a bit - the UI interaction in that example is most certainly broken as it stands. I'm not sure I can make what you are looking for happen, but it shouldn't be possible for the user to get it into that state in the first place.
Allan
Thanks, Allan.
I'm working on a workaround.
Do you see any problems with the following plan?
Button for creating a new site brings up a form. This form:
1. does not show the users table.
2. Has a custom button labeled "create site and add people"
The custom button's action is:
1. Submit the form.
2. Capture the newly created row-id
3. Select this row.
4. Trigger the edit menu which does include the users table.
I've tried implementing it, however custom button's actions don't seem to have access to their datatable (the documentation suggests they should). The following code results in the console logging "undefined" for
dt
,node
, andconfig
. Do you have any suggestions?I answered this in your other thread.
@allan is the person to answer about your approach.
Kevin
Kevin's comment in your other thread on this topic is spot on the money as always.
With regard to your approach, yes, I think that is fine. There might be a fair bit of nesting code, but I think that will do it okay as long as you can reference the right tables.
Allan