Say I have a custom field customField1 in the current transition screen and I have behaviours that may set that customField to error
def customField1 = getFieldByName("customField1")
<Some condition>
customField1.setError("This field has an incorrect value")
or
<Some other condition>
customField1.clearError()
is there a way to inspect the field to see if it currently has an error?
may be something like
customField1.hasError() that returns true if the field in the form is supposed to be showing an error like after the <Some condition> example above or false if the field is the form is not supposed to be showing an error like after the <Some other condition> example above.
Hope this makes sense. Thanks
FormField has a #isValid() method. Could try that out.
Tried that after you suggested it but didnt work. isValid() method seems to work if instead of setError(Error String) I use setValid(false).
When would one use setError() and when setValid()? Wondering if there is any "official documentation" or best practices document that explains when to use each. The setValid() doesnt support the setting of text (presumably HelpText) to tell the user why the field contains an invalid value so you have to combine this with setHelpText() if you want / need that. The Error String in setError is actually used to setHelpText(), and presumably it sets some unreadable status of the field, but it doesnt seem to be the isValid status.
The other thing that I noticed that that those inspection methods (isValid(), isReadOnly(), isRequired(), etc) ALWAYS return false unless you have explicitly set or changed the values on the same script. So either I don't understand how these are meant to be used or there is bug.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, it seems that even if you set a field as invalid with setValid(false), the user can still complete the transitions where are with setError(), the user cant complete the transition unless the error has been cleared (clearError()). So at least for my use case, setError() gives me more of what I need, except that I cant inspect a field to determine if it has a setError.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like setError changes isValid to false, but clearError does NOT change isValid to true.
Also,
If you setValid to false, you can still complete the transition with the invalid entry.
Its just very strange the way this works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So you can end up with fields for which you get isValid = true, but cant still complete the transition because you didnt clearError().
You can also end up with fields for which you get isValid = false, but you can complete the transition.
If we are meant to only use setError and clearError, then shouldnt there be a method to check if a field is in this Error state ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
worse you can replace the error message with setHelpText('All is fine') and you end up with a field that returns isValid = True, a Help Text that says "All is fine", and still not be able to complete the transition
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.