I need to add a red border around an input field, when some conditions are met:
if (...) {
$('#node-input-myfield').addClass("input-error");
}
This works fine when this code snippet is called e.g. in an onchange event handler.
However the class is not available on myfield, when I call this code snippet in oneditprepare.
I 'assume' that is because myfield is not yet visible at that moment?
Does anybody know how I can solve this?
Oneditprepare should be able to add class to any element.
I assume myfield is one of the node's properties listed in its defaults object? If so, have you also set a validator function and/or set the required flag?
One possible explanation is that the editor will be validating your node after oneditprepare and if there's no error, it'll clear the input-error class.
Hey Nick,
Indeed I had a validator that was not functioning correctly yet.
After fixing that, I could remove my addClass call in the oneditprepare (since the validator adds the class now). That was very stupid logic in my code...
Thanks again!!
Bart