On Create only - set select2 data
On Create only - set select2 data
![RichJCG](https://secure.gravatar.com/avatar/2919899e5d26dc707003ba945784b6e5/?default=https%3A%2F%2Fvanillicon.com%2F2919899e5d26dc707003ba945784b6e5_200.png&rating=g&size=120)
Essentially, I have 2 tables that load projects and upon selecting a project row loads the set cost codes into the second table. All works properly on edit and remove.
We have a standard list of cost codes that I would like to load into a select2 and show only when I Create a new record. This would then use the code and description from the standard list and add to the projects code table. I feel comfortable getting the ajax data loaded but not sure where to start to setup the form to only show the standard list of codes on create only. Any help in pointing me in the right direction is greatly appreciated.
This question has accepted answers - jump to:
Answers
There are a few options here:
field().show()
andfield().hide()
) - use theinitCreate
andinitEdit
events to call those methods.initCreate
to dynamically add the Select2 field (add()
) and then remove it (clear()
) onsubmitComplete
.Regards,
Allan
Great information - field().show() actually helps with something else I'm just starting to work on as well.
Agree on Option 1 probably being the easiest.
If I went with option 2 my question would be - How do I load an unrelated table into the php Editor instance?
Something like below where projects is the main table and eq_rental would be the unrelated table? Not sure if that would work as I wouldn't be able to join those two tables.
Not quite sure what you mean by "unrelated" in this case I'm afraid. You can load "related" information from another database table using a left join - but you wouldn't have a single form controlled data for two different and unreferenced tables.
Allan
By "unrelated" I mean there is no way to join them together, as you stated that's not going to work.
I think I will go with initCreate and add the field dynamically. The edit action will only happen once the code has been added to the project so shouldn't need anything out of the ordinary there.
Many thanks.
Daft question perhaps, but if you can't join them together, how do you combine them to display in a single table row?
Allan
Not actually showing two sets of data in a single row.
The standard list of codes table only has two pieces of information - the code number (01-1000) and the description (Safety Labor). That code gets selected and then the budget, labor hours, etc is added and stored in the project_code table. So I'm copying the standard code information into the project_code table.
I'm doing it this way as we don't allow non-standard codes to be added to the projects. Once it's added they can edit and change budget or total labor hours - they just can't change the code. That's why I only need it to happen when creating a new code.
I could reference them to each other but there are custom descriptions that can be modified per project so it's not always matching.
I'm with you now - thanks for the explanation.
initCreate
sounds like a good approach.Regards,
Allan
So here's my next question(s). I've added
below my codeEditor definition. I am able to see the code data come through
I get no errors but unable to get the codes to load into the select.
Maybe too many "codes" haha. Any pointers greatly appreciated.
By default Editor looks for
label
andvalue
properties in the object, while you havecode
anddescription
. You could change them, map them or use theoptionsPair
object ofselect
to define your own code and description properties as the ones to use.Allan