->data() with custom validation and throw message...?
->data() with custom validation and throw message...?
Hello,
i use datatables editor with ->data()
...
$data = Editor::inst( $db, 'MY_TABLE', 'Id' )
...shorted...
->process( $_POST )
->data();
// Additional example data...
$addtionalData['foo'] = "bar";
$result = [
'data' => $data['data'],
'additional' => $addtionalData
];
echo json_encode($result, JSON_PRETTY_PRINT );
My Problem is now, send error messages via throw, back to the editor. As Example:
->on('preRemove', function($editor, $id, $values) {
if ( $id == 1 ) {
throw new Exception('<span>Example error (this item cannot removed!)</span>');
};
})
The throw will not execute. After click the 'remove' button on the editor modal frontend, the editor close without any messages and remove the item.
If i remove the ->data();
and change to ->json();
it works well...
Answers
You are copying across the
data
parameter to your$result
assoc. array, but not any of the other fields - e.g.fieldErrors
orerror
.Why not just do:
That way you are returning the original assoc. array that Editor builds with the data to send back to the client?
Allan