Displaying SQL constraint errors for inline editing
Displaying SQL constraint errors for inline editing
I've got a SQL table that has a constraint on it (UniqueMarker) to prevent identical records being created with the same 3 ID keys. I added the following code to my JS to detect when a SQL error was being returned, and to check if the constraint name was mentioned within that error.
// Test for SQL errors based on constraint name, and display user-friendly message instead
markersTableEditor.on('postSubmit', function (e, json, data) {
if (json.error) {
if (json.error.indexOf('UniqueMarker') >= 0) {
json.error = "This person has already been assigned as a marker for this module and year.";
}
}
This works great when using the pop-out editor window, as it replaces the ugly error returned from SQL with the more user-friendly message I've written above. When performing inline editing on a table, however, the edit will simply fail without displaying a message if it infringes on the constraint.
I thought I might be able to use the "unique" validator from Editor's PHP library, but I think this will only work on one particular field and not on all 3 keys.
Is there a way of getting the SQL error to be displayed when performing an inline edit, or a validator that can be used against multiple fields simultaneously?
This question has an accepted answers - jump to answer
Answers
When inline editing, only the current field can be edited, and as such only its error message can be displayed (it is assumed that all other fields are currently valid). I'm afraid there is no way to have the global error message displayed at the moment when inline editing - which is a flaw I'm aware of and will address in future.
At the moment you'd need to return a field error, rather than a global error.
Regards,
Allan