inline edition unique validation for two columns
inline edition unique validation for two columns
I need to validate that the combination of two columns in the row is unique.
I found in the forum this custom validation:
https://datatables.net/forums/discussion/57729/unique-validation-for-multiple-columns
$count = $editor->db()->query('select')->get('*')->table('teachers_subjects')
->where('teachers_subjects.teacher', $values['teachers_subjects']['teacher'])
->where('teachers_subjects.subject', $values['teachers_subjects']['subject'])
->exec()
->count();
I did it and it works fine in the editor pop-up. The validator works fine when editing and when creating a new row.
But it doesn't work for inline editing. It drops a SQL error is the combination of the two columns is not unique.
How to make this validation work for inline edition?
This question has accepted answers - jump to:
Answers
I am using unique indexes and the resulting SQL error if violated to generate client side error messages. That should be working here as well:
Thanks
It is not ideal, but it works.
So... better done than perfect.
I will use your method.
Well you could also fix your inline editing differently. You are probably not submitting all values to the server when you do inline editing because not submitting everything is the default. And that will be the cause of your problem. I found that too difficult ... but is is up to you. If you are willing to deeply analyze this ... your decision.
When I do inline editing I usually use this to avoid the problem right away:
Check this:
https://editor.datatables.net/reference/option/formOptions.main
and this please
https://editor.datatables.net/reference/option/formOptions.inline
Using the form has: submit: 'all'
while inline editing has: submit: 'changed'
as defaults
I found that 'allIfChanged' works fine for inline editing because whenever anything gets changed ALL values are submitted which should make your validator work which is based on two field values.
Sorry if my answer seemed rude. Not my intention.
I really appreciate your first answer which solves the issue in a fast and easy way.
And the second answer is very helpful and will keep in mind for future cases.
Again, thank you very much.
Hei rf1234,
Your answer was useful, so accepted, but I don't know how to accept it. Sorry. Apologize.
To be able to mark a reply as accepted, the thread needs to have been started with the New Question button rather than New Discussion. I've moved this thread over.
Allan