Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation-on-blur suport #29

Open
nighca opened this issue Jul 3, 2020 · 2 comments
Open

Validation-on-blur suport #29

nighca opened this issue Jul 3, 2020 · 2 comments
Labels
discussion More discussions required enhancement New feature or request

Comments

@nighca
Copy link
Collaborator

nighca commented Jul 3, 2020

Now formstate-x uses validation-on-change mode (with debounce). Validation-on-blur is also a common use case. It is important to support such case officially.

@nighca nighca added the enhancement New feature or request label Jul 3, 2020
@nighca nighca added the discussion More discussions required label Apr 18, 2022
@mattleonowicz
Copy link

For now, I just do this as part of my bindField utility:

interface Additionals {
  onBlur?: (e?: React.FocusEvent) => void;
}


export function bindField<T>(fieldState: IState<T>, { onBlur }: Additionals = {}) {
  return {
    value: fieldState instanceof DebouncedFieldState ? fieldState.$.value : fieldState.value,
    onChange: (value: T) => {
      fieldState.onChange(value);
    },
    onBlur: (e?: React.FocusEvent) => {
      onBlur?.(e);
      fieldState.validate();
    },
  };
}

If onChange doesn't require this workaround, then onBlur might make sense too.
But if you do this, you might start getting requests for the possibility to turn it off (for some edge cases).

@nighca
Copy link
Collaborator Author

nighca commented May 12, 2022

Thx for your feedback @mattleonowicz

It seems that in your sample code, validating will be automatically triggered both when blur and when change — something like validate-on-(change|blur)?

I thought if someone wants validate-on-blur, he may not want validate-on-change at the same time. While that's little difficult to workaround with formstate-x now.

But if you do this, you might start getting requests for the possibility to turn it off (for some edge cases).

Yeah you are right. Validate-on-blur, validate-on-submit & no-(auto)-validate, the three need to be considered together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion More discussions required enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants