Add icon before field error message
Add icon before field error message
Hi,
I'm using Editor with PHP, and I'm trying to add an icon before the error message.
I used to inject the icon directly in the backend but I'm tyiding things up.
I though I could use onFieldError inside formOptions as such:
formOptions: {
main: {
...,
onFieldError: function (editor, error) {
var fieldName = error.name;
var errorMsg = error.status;
var iconHtml = '<i class="bi bi-exclamation-circle-fill"></i> ';
var customErrorMsg = iconHtml + errorMsg;
editor.field(fieldName).error(customErrorMsg);
}
}
}
but with this, I only get the icon on the first field error message: all the others just have the error message.
Doesn't onFieldError automatically apply to all errors?
This discussion has been closed.
Answers
What I would suggest doing here is listening for
postXhrand checking to see if there is afieldErrorsarray on the JSON object, and if so, looping over it modifying the status string as needed.The current
onFieldErrordoesn't work for anything other than the first field in error as I explicitly have ai === 0index check before executing the callback. The idea there was the if the function changes focus (which is how I was expecting it to be used) then you only want that to happen for the first field, not all of them.Perhaps that needs to be changed. Certainly the docs need to mention this - apologies for that oversight. I'll do that just now.
Allan