Skip to content

Do you have any possibility to check for a field to be pristine/touched? #21

Open

Description

@ckpinguin

Somehow it should be possible to only check validation, if field is touched or onBlur (switch to the next field)?

Activity

  1. gaperton commented on Apr 20, 2017

    @gaperton

    Create your own <Input /> tag which behaves like this. This is the normal way of handling such a situation in the way needed for you.

    For the start copy Input implementation from tags.jsx. Then change the way how it handles the validation error which is enclosed in the link. There is no magic at all, the creation of your own controls is straightforward:

    https://github.com/Volicon/NestedLink/blob/master/tags.jsx#L35

    Your Input must know whenever it's focused or touched and suppress displaying the validation error if it's not. Probably, you will need to add the local state to it to make it remember such a thing.

  2. gaperton commented on Apr 20, 2017

    @gaperton

    You're supposed to create your own controls wrapping all necessary styles and handling error formatting, in the way that your forms will be defined with the semantic markup. That's an overall idea and links makes it practically possible. tags.jsx is just an example and the starting boilerplate.

    That's how it is done in userslist example:

    const ValidatedInput = ( props ) => (
        <div>
            <Input { ...props } />
            <div className="validation-error">
                { props.valueLink.error || '' }
            </div>
        </div>
    );

    https://github.com/Volicon/NestedLink/blob/master/example/src/userslist.jsx#L150

    You need to do the same thing but use raw <input/> and add the local state to make it remember whenever it was touched. That's it.

  3. ckpinguin commented on Apr 21, 2017

    @ckpinguin
    Author

    OK, thanks I'll try it :-)
    Yesterday I „solved“ it using onBlur={() => this.setState({titleTouched: true})} but having more local state in a subcomponent did not feel right.

  4. gaperton commented on Apr 21, 2017

    @gaperton

    Yesterday I „solved“ it using onBlur={() => this.setState({titleTouched: true})} but having more local state in a subcomponent did not feel right.

    It is okay. You need to hide this local state in <Input/> itself once and forget about it. This state is entirely private and there is no reason to expose it outside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions