This PHPMaker 2024 project will show you how to hide the options in Select2 control if already been chosen in another row from Grid-Add mode. If the option has already been chosen from Select2 control in a row, then it will no longer be exist in Select2 control in another rows with the same column.
To achieve this, then we can handle it so easily from Client Scripts. We may simply write jQuery code in order to hide the options that already been selected in the previous rows, so that it will not be displayed anymore in the next rows of Grid-Add mode.
There are three tables in this project. The first is colors, the second is trademarks, and the third is cars. In the cars table, there are two fields that will store Trademark and Color of the cars.
So, based on trademarks table, we can add multiple Colors for a Trademark by using Grid-Add mode that belongs to the cars table.
For example, in Suzuki trademark, we hit a button named Set Colors to Car, then system will open Grid-Add mode of cars table. The number of rows in Grid-Add will depend on how many records of Colors that do not exist in the cars table.
Now here is the most interesting part. After choosing Black color option for Suzuki, then this Black color option will be removed from Select2 control in another rows in that Grid-Add mode. This will help End-Users to quickly choose another Color which has not been selected for the certain Trademark.
We will learn many things from this project:
- How to use Lookup_Selecting server event in order to filter the options if it has already been used.
- How to filter the options in Trademark field in cars table, based on Trademark param that sent from another table.
- How to hide the options from Select2 control after have been chosen in another Select2 control in Grid-Add mode.
- How to add a new button on each row in List Page in order to open Grid-Add mode that belongs to another table.
- How to add icon on button and change the color of button on each row in List Page.
- How to make the button disabled on List Page based on the certain condition in another table.
- How to limit the number of rows in Grid-Add mode based on the number of rows in another table.
- How to change the default Duplicate Key error message when editing an existing record.
- How to save Date Added and Date Updated in background stage while adding multiple records via Grid-Add mode, or while editing single record from Edit Page.