Automatic value in order column of new record
Automatic value in order column of new record
Hello,
I am using editor v 2.0.4 and I am looking for best method to restrict users to enter value by them self in order related field of editor form.
I want to create process that is automatic, so the new record will be always "max value + 1"
I have two quick ideas:
1st is to use postCreate and execute custom SQL that is including result from code below and update newly created record:
SELECT IFNULL(MAX(readingOrder)+1, 1) FROM test
But still user needs to enter sth in the filed because RowReorder plugin needs that...
Without that data I am getting
An SQL error occurred: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'readingOrder' at row 1
Maybe setting some default will skip that, but then I need to hide that filed because data will be generic and it will confuse users...
2nd is to use Field Defaults but since it is on JS side, data will be loaded (ajax call? of mentioned select) probably right after the editor window will popup so if 2 users is going to open edit window in the same time, they can finish with same order values
https://editor.datatables.net/examples/simple/fieldDefaults.html
Is there any other more fancy method?
TBH since You have integrated rows order recalculation while deleting some element (except last one) I am surprised that such behavior is not default
This question has an accepted answers - jump to answer
Answers
The first option is the one I would use myself, for exactly the multi-user reason you describe on the second option.
To be honest, I hadn't thought of it! Here is how it can be done:
Allan
Thank You Allan!! It works like a charm!