qiniu / formstate-x

Manage state of form with ease.
https://qiniu.github.io/formstate-x
MIT License
33 stars 10 forks source link

`ownError` for `IState` #71

Closed nighca closed 2 years ago

nighca commented 2 years ago

When we do UI binding for validate status, such as error tip showing, invalid highlighting. Most of the time it produces UI like:

image

image

If the bound state is composed with child states, which means the child states may have been bound to some child inputs or error tips. It's not necessary to show child states' error at parent level—that will introduce duplication.

Here is an example of FullNameInput, which consists of input for first name & input for last name. If we use error (& hasError) for UI binding, the error of first name (Please input!) will be shown at both child level & parent level:

image

That's why ownError (& hasOwnError) is needed.

We will always prefer to use ownError (& hasOwnError) for UI binding. That will help to avoid error duplication.

Previously we provide ownError (& hasOwnError) for FormState (& ArrayFormState) only. While considering a instance of DebouncedState or TransformedState, which wraps a FormState instance, ownError is also needed for it. In the future, we may provide more state types just like DebouncedState & TransformedState, for whom ownError is also needed.

That's why I think we should put it on interface IState.