on-demand validation option

Issue #226 open
Hadi Fakhreddin
created an issue

Hi team,

Thanks for your fantastic work in ControlsFx.

I started using ControlsFX recently and specially started with validation. I have two suggestions for validation.

1- To have an option for on-demand validation only as opposed to validating at every change to the control. This for example will happen when the form is submitted.

validationSupport.registerValidator(username, Validator.createEmptyValidator("Username is required"), ValidationMode.ON_DEMAND)

Then wen needed the following is called for validation:
boolean isInvalid = validationSupport.isInvalid()

Then the above code will go and

(Note: the on-demand declaration is similar to "jideFx-validation")

2- At the moment the validation is done even in the initial part and before any interaction is done by user. So for example as soon as a form is rendered, the mandatory TextFields have the red cross on the left. This can confuse the user seeing a form being loaded with errors. I am after an option to postpone displaying the error/warning indicator to after an interaction. This might be considered as the default behavior. The first option can partially address this since no validation is done until explicitly requested .

Comments (9)

  1. Eugene Ryzhikov

    After some investigation, it seems that the best solution would be an ability to show/hide validation decoration. Since the validation framework is pretty generic and detached from any window/form lifecycle, one would be able to turn off validation decoration rendering until full initialization is finished. Initialization may include all kind of things, including field data assignment. Note, only "errors/warnings" decoration will be affected, "required" decoration will be always on.
    Thoughts?

  2. Paul Furbacher

    I wasted a lot of time trying to refactor ValidationSupport to provide such "on demand" validation. I tried adding a validate() method, and instead of "registering" validators, added them to a store, and then "registered" them on demand. The problem is that in this (ControlsFX) implementation, validation depends on value changes in the registered controls. When you "register" on demand, there aren't any changes occurring so things aren't validated.

    ValidationSupport works only if the change listeners are in place from when you first show the form, prior to any editing. But that isn't the way most people approach validation. When was the last time you encountered a Web form which nagged you about validity prior to submitting the form? It's just not the way it's done.

    That said, after many hours of frustration (the code is perhaps unduly complex and doesn't cover all controls -- e.g., what about RadioButtons?), I was about to implement my own validation specific to the app I'm working on (no time to generalize to a framework). I was on the elliptical while my daughter was in swim practice when it suddenly hit me: the easiest way to handle this "on demand" requirement would be to just let the framework do its stuff, but don't give it a decorator which does something until the "submit" button is pressed. Bingo, that works. (Still doesn't give me validation of RadioButtons, but that's for a separate JIRA issue.)

    public class NullValidationDecoration extends AbstractValidationDecoration {
    
        public NullValidationDecoration() {
        }
    
        @Override
        protected Collection<Decoration> createValidationDecorations(ValidationMessage message) {
            return Collections.EMPTY_LIST;
        }
    
        @Override
        protected Collection<Decoration> createRequiredDecorations(Control target) {
            return Collections.EMPTY_LIST;
        }
    
    }
    
  3. Adam Arold

    So is there some progress with this? I'd really like to use the validation support when the user clicks the submit button in my app but I can't get this to work. I tried

    vs.setErrorDecorationEnabled(false)
    vs.setErrorDecorationEnabled(true)
    vs.redecorate()
    

    but it does not work either.

  4. Log in to comment