I want to be able to optionally include an "Add new" link in a form associated with a relationship selection.
That way, users can either selecting an existing post for the relationship, or add a new post for the relationship - exactly as you can do within the WordPress backend!
I can easily add a link in the form, and I've figured out how to display the required 'add new' form in a bootstrap modal.
The tricky bit, which I've not tackled yet, is being able to adjust the drop-down in the original form's relationship selector to include the newly-created post, and make that the selected value.
This will be needed both for normal forms AND relationship forms.
Before working on this, I thought it worth asking whether this feature is on your development path - it seems like a very useful feature, which you've already recognised as being important for backend relationship handling: I've found that exceptionally useful in building out my own back-end data structures, so I want to be able to provide the same feature to my future users.
If this isn't on your near-term development path, do you have any tips on the best approach?
I'm assuming this is going to be a job for jQuery, right?
Thanks
Alex
Hi, I think you'll definitely need some JavaScript and possibly jQuery to do what you're looking for. You'll have to create some kind of AJAX application that allows you post a request via AJAX and automatically create a post of some kind and return its ID. Then you'll have to inject that value into the select field along with the post title. So there are two roadblocks here:
- No Toolset APIs are involved to create the post, so I can't help you there.
- No Toolset APIs are involved to modify a post relationship field, so I can't help you there either.
I can help you implement the post relationships API if necessary to connect two posts.
I can't see this feature on our immediate schedule, though improving the post relationship Form experience is on the long-term roadmap.
At least I know I won't be duplicating work Toolset will be doing.
Thanks, Christian.
Alex