question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Form] validateTrigger not working with values other than onChange

See original GitHub issue

Version

2.11.1

Environment

Chrome 59.0.3071.104 / Windows 10 64-bits

Reproduction link

https://codepen.io/anon/pen/awmVjK?editors=0010

Steps to reproduce

  1. Type something in both inputs
  2. Observe the green mark appearing as you type on the right-hand side of the inputs

What is expected?

The inputs should not be validated until a blur event happens for the first input, while the other should never be validated (the validateTrigger option’s values are onBlur and false, respectively).

What is actually happening?

Both inputs are validated as you type, as if the value for the validateTrigger option was the default onChange.

Weirdly, if you type something in the first input, then delete everything you’ve just typed and unfocus the input, it will start working properly (the input will only be validated as you blur).


I’m trying to setup a form that only displays errors/valid marks when the users clicks on the submit button, not as the user types.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

31reactions
Nuokycommented, Oct 25, 2018

@acomito Try this, it works for me

{getFieldDecorator('email', {
  validate: [{
    trigger: 'onBlur',
    rules: [
        { required: true, message: 'Input your Email!' },
    ],
  }, {
    trigger: 'onChange',
    rules: [
        { type: 'email', message: 'The input is not valid E-mail!' },
    ],
  }],            
}
27reactions
acomitocommented, Aug 27, 2017

It would be nice to be able to add it per rule:

{getFieldDecorator('email', {
  rules: [
	{ required: true, message: 'Input your Email!', validationTrigger: 'onBlur', },
	{ type: 'email', message: 'The input is not valid E-mail!', validationTrigger: 'onChange',},
        { max: 100, message: 'Must be no more than 100 characters!', validationTrigger: 'onKeyUp', }
 ],
})(
   <Input prefix={<Icon type="mail" />} placeholder="Email" />
)}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ant design Form validateTrigger change dynamically from ...
This type of validation has worked for me: <FormItem {...formItemLayout} label="E-mail" hasFeedback > {getFieldDecorator('email', ...
Read more >
validateTrigger.js - example - rc-form@2.4.12 - react-component
use validateTrigger config ... email validate onBlur && onChange ... formShape } from 'rc-form'; import React, { Component } from 'react'; import ReactDOM ......
Read more >
Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles.
Read more >
ant-design/ant-design-english - Gitter
hi all - I'd like to have a form validation trigger pattern that is initially onBlur, then onChange after the first validation fail,...
Read more >
Antd: How To Validate Form Items Values Has Been Changed
Includes layout initial values validation and submit. import { Form Input ... [Form] validateTrigger not working with values other than onChange # The ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found