Question

When choosing 'Add' in CRUD, how best to generate a list of choices to pick from a dropdown?

For U/update - just display what's there...

The field contents starts with a letter, followed by five numeric digits:{A-I,K-N,Z}#####

Each letter has a different 'max' value for the numeric part.

So when adding a new record, I'd like to offer a listbox with one of each letter and that letter's highest numeric value + 10.

So, if the max 'A' as A00120, and max 'B' B00030 (etc) the listbox would have A00130 and B00040.. etc

Save the user having to figure out which is 'next' when generating a new record.

? Thanks,

Mark

Was it helpful?

Solution

This time I'll not be able to come up with ready to use solution, but I must say - everything is possible with ATK4. You just have to customize and extend it to fit your needs :)

Speaking about your question above - I guess you have to split it in multiple parts.

First part is about how to show select box on Create and readonly or disabled field on Update. I guess you can make some custom Form field or pin some action to existing Form Field hook. Not sure exactly what's better in this case.

Second one is about data structure. I believe that this field actually should be 2 fields in DB and maybe (only maybe) merged together in ATK model with addExpression() just for user interface needs to display these 2 fields as one field easily in UI. Maybe such concatenated field will be useful also for searching, but definitely not as only one field stored in DB. Imagine how hard it'll be for DB engine to find max value if such field. Store it like type = letter, num = number and then search like SELECT max(num)+10 FROM t WHERE type='A'

Finally Third part is about how to generate this next number. I read your question 3 times and came to conclusion that actually you don't have to show this +10 numeric value in UI at all if it's hardly predefined anyway. Actually that'll not work correctly if this will be multi-user system which I guess it will. Instead just show simple select box with letters {A-I,K-N,Z} and calculate this next value exactly before inserting data in DB. That can be done using models insert hook. This will be much more appropriate solution and will be better for UI and also more stable because calculated in model not incorrectly in UI part.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top