Mit dem jQuery-Datentabelle-Editor-Plug-in funktioniert der folgende Code wie vorgesehen. Es führt bestimmte Validierungen durch (einige Felder wurden der Kürze wegen weggelassen).Validierung mit Inline-Bearbeitung in jQuery-Datatabellen nach dem Anpassen von Leerstellen
Editor::inst($db, 'file_upload')
->fields(
Field::inst('id')->validator('Validate::notEmpty'),
Field::inst('name')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
return $length > 30 ? 'Length must be 30 characters or less' : true;
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('document_title')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
return $length > 50 ? 'Length must be 50 characters or less' : true;
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('email_address')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
return $length > 60 ? 'Length must be 60 characters or less' : true;
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
})
)->where(function ($q) {
$q->where('file_type', "('jpg', 'jpeg', 'gif', 'png')", 'IN', false);
})->process($_POST)
->json();
Aber wenn die Validierungslogik ist etwas wie das folgende geändert,
Editor::inst($db, 'file_upload')
->fields(
Field::inst('id')->validator('Validate::notEmpty'),
Field::inst('name')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
// The following line has been modified
return $length === 0 ? 'This field is required' : ($length > 30 ? 'Length must be 30 characters or less' : true);
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('document_title')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
// The following line has been modified
return $length === 0 ? 'This field is required' : ($length > 50 ? 'Length must be 50 characters or less' : true);
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('email_address')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
// The following line has been modified
return $length === 0 ? 'This field is required' : ($length > 60 ? 'Length must be 60 characters or less' : true);
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
})
)->where(function ($q) {
$q->where('file_type', "('jpg', 'jpeg', 'gif', 'png')", 'IN', false);
})->process($_POST)
->json();
In diesem Fall Validierungen durchgeführt werden, wie sie sollten aber Werte werden nicht vorgelegt (und gleichzeitig die Datentabelle nicht aktualisiert) zur Datenbank. Das Inline-Bearbeitungsfeld bleibt geöffnet, nachdem die Eingabetaste gedrückt wurde.
Was könnte der Grund sein und wie man es beheben kann? Möglicherweise entgeht mir etwas ganz Einfaches über PHP.
Ich werde das entsprechende Client-Skript bei Bedarf veröffentlichen.
Es scheint, dass andere Validierer werden ausgelöst, wenn zusätzliche Bedingungen erzwungen werden verhindert Eingabewerte aus auf die abstrakte Ebene vorgelegt werden, Datenbank. Dies sollte nicht bei der Bearbeitung von Inline-Zellen passieren.
Was ist das Heilmittel?