You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems attribute "#required" on a 'file' FormElement leads to a bug that displays a missing file error no matter what...
However, we have our convenient custom validator for that '#element_validate' => ['::validateFileupload'],
The first thing file_save_upload does, it checks there is actually a file. If none, it returns NULL. In case of error though, it returns FALSE.
So we can make a first check and add a specific error message for missing file:
$file = file_save_upload('csvimport', $validators, FALSE, 0, FileSystemInterface::EXISTS_REPLACE);
if ($file === NULL) {
$form_state->setErrorByName('csvimport', t("Missing file"));
}
elseif ($file) { // != FALSE
}
else {
// The line below prevents the submitForm function to be called. The errors added by file_save_upload will be displayed
$form_state->setErrorByName('csvimport', '');
}
The text was updated successfully, but these errors were encountered:
It seems attribute "#required" on a 'file' FormElement leads to a bug that displays a missing file error no matter what...
However, we have our convenient custom validator for that '#element_validate' => ['::validateFileupload'],
The first thing file_save_upload does, it checks there is actually a file. If none, it returns NULL. In case of error though, it returns FALSE.
So we can make a first check and add a specific error message for missing file:
The text was updated successfully, but these errors were encountered: