a select with several dynamic field updates
a select with several dynamic field updates
Hello
In order to finish my project, I realized a malfunction.
I'll need a concrete example (js + PHP) to do this (to understand the mechanics):
I have a controle
table and a warehouse
table with the appropriate foreinkeys
when I choose a warehouse in my select, I need the fields of my form (modal)
to be dynamically updated with information from the database of the entrepot
table only when 'EDIT' is performed.
Thank you very much for your clarifications (this is my last hurdle to close my project ).
Replies
What's the relationship of the
entrepot
table to the other two?When you are doing an edit, which table is the primary table you are editing on?
Allan
hello Allan,
There is the table:
The
controles
table (main)and the
equipments
tableCurrently, if I select another warehouse with the SELECT via EDIT, the warehouse name changes but not the other fields corresponding to warehouse.
and the
entrepots
table is updated with the information from the old warehouse.example of what's happening now,
entrepot
table:Warehouse1: 15 rue des Lilas 75000 PARIS
Warehouse2: 30 rue des Rose 21000 DIJON
if I select Entrepot1 in NEW, no worries, I get
Entrepot1 : 15 rue des Lilas 75000 PARIS
but if I change Entrepot2 in EDIT, I validate :
Entrepot1: 15 rue des Lilas 75000 PARIS
Warehouse2: 15 rue des Lilas 75000 PARIS
The reaction is normal since I didn't reload the right information before validating.
That suggests to me that the data for the whole row is not being returned to the client-side. Can you give me a link to a page showing the issue please? You can PM me the link if you can't make it public.
Allan
Hello Allan,
I sent you the link by PM
Thank you.
Hello Allan and everyone,
I managed to retrieve the warehouse ID with my SELECT field from the MODAL window. Every time I select a warehouse name, it returns the warehouse ID and full address.
Here's the code used PHP :
Get_details_entrepots.php?entrepotID=4
JSON return
Now comes the most complex part for me,
I need to replace the values of 5 fields with the JSON return in the MODAL window immediately after changing the value of my select without clicking Update and without closing the MODAL window.
Here's the poor code I've come up with, but I can't figure out how to do it.
The 5 fiels are :
A lot of help would be welcome, thank you
Don't combine the result in the JSON data - you really want it to return the value for each field:
Then you can populate each field with the value, rather than needing to try and parse the string. It isn't a list of options you are returning - is the the values for a specific entry, so you don't need an array. Also don't call
field().update()
you aren't changing the list of options. You are however changing values, so you might use:As I mentioned in my PM you can use
dependent()
to do a lot of this, but this way works as well.Allan
My code dependent JS :
My code PHP :
and it works perfectly !
Thanks a lot Allan!