editor presubmit message
editor presubmit message

Hello!
I am checking for duplicates in the database and returning an error. It works fine. What I want is to display the user some kind of warning message that this input already exists and still let him create a row. Just a notification about the presence of a duplicate. How should I change the code?
I took this forum topic as a basis https://datatables.net/forums/discussion/12650/check-for-duplicates/p1.
Thanks in advance!
Field::inst( 'name' )
->validator( function($val, $data, $opts) {
global $db;
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$checkdup = $db
->select( 'users', 'id', array(
'name' => mysqli_real_escape_string($link, $val)
) )
->count();
if($checkdup !== 0){
return "Duplicate name.";
}
return true;
} ),
This discussion has been closed.
Answers
You would need to have an additional (hidden) field which would tell the validation function to skip or not. e.g. in pseudo code:
On the client-side you'd have a
postSubmit
event that would check for this validation error / warning, and set thehidden
field value so the validation would skip on the next submission (e.. set it to true). Remember to set it to false whenopen
happens so it resets for the next insert.Regards,
Allan