8000 [Question] Validate only if field is dirty · Issue #62 · gtournie/redux-form-validators · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[Question] Validate only if field is dirty #62
Open
@mariomeyrelles

Description

@mariomeyrelles

Hello,

I am using Final Form. I have an e-mail field that is optional.

How would you validate only if the user tried to enter a wrong e-mail? I have succeeded to do this but I didn`t like the solution:

import * as vld from 'redux-form-validators';

<Field name="email" label="E-mail de Contato" placeholder="Deixe seu e-mail" component={TextInputField} validate={emailIfNotEmpty} />

The custom validator code is like this:

const emailIfNotEmpty = (value, allValues, meta) => { if (meta.dirty) { return vld.email()(value); } }

Can you suggest a better approach?

Kind Regards,
Mário

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0