Field error on upload field AJAX
Field error on upload field AJAX
Hi,
I have an upload field in one of my tables. I am using my own AJAX for the upload and I based on one of the forums questions (https://m.datatables.net/forums/discussion/34957/editor-upload-file-handling-ajax).
I am preventing the upload and returning an error message to the user if the file is not within a set of requirements.
The error is showing at the bottom of the edit screen, which is good. However, I also would like to have a field error and I am not sure how to do that.
Below is what I am returning from AJAX. I tried using 'uploadField.error' but that didn't work, it seems it's ignoring it. I swapped it with 'error' and it's still ignoring it
Thanks!
if($OKFlag == 1)
{
$return = [
"files" => [
Table" => [
$id => [
"filename"=> basename($_FILES["upload"]["tmp_name"],$UploadFileType),
"web_path"=> $path
]
]
],
"upload"=> [
"id"=> $id
]
];
}
else if($OKFlag == 0)
{
$return = [
'uploadField.error' => [
$UploadMessage // Only in case of error
],
'error' => [
$UploadMessage // Only in case of error
]
];
}
echo json_encode($return);
}
This question has an accepted answers - jump to answer
Answers
Hi,
I would suggest using the documentation here which documents the file upload now (it didn't when that forum post you linked to was written). It also documents how to return field specific error information using the
fieldErrors
property (see specifically this example).Allan
Oops; I totally missed the example! Thanks. That did it!