I’m sure I’m missing something simple but I’m stumped.
I have a multi-select field which gets a list of categories from the tbl_categories table. I then have a table tbl_stocks which has a list of stocks and a table tbl_stock_categories which stores the category id’s associated with each stock id.
First of all what I need is to be able to have the multi-select field select the already selected values from the tbl_stock_categories table. Then when I save the form I need those values to update if they’ve been changed.
I suppose I could just put a category_ids field in the tbl_stocks table but if there was a straightforward way to do it with my current database structure I would prefer that.
Use a repeat with the array of categoriy_ids passed in the form value to the server connect, adding each ID to the junction table with the selected stock_id
How do I pre-select the items that are already in tbl_stock_categories (junction table) .
So for the category select for stock_id 66 categories 1 and 2 should be selected when the form is opened.
Also - I’m updating so just adding those values to the tbl_stock_categories table won’t work. I guess I could just delete any current records and then add the new ones.
It’s returned in a JSON array naturally - so you’ve got the IDs you need form the SELECT query. When posting the values back, you would first clear all the values then add the select_id items back