Redux Form always validates even on a normal button press - reactjs

I have a redux form with a submit button and a normal html button. I dont want the form to be validated when the normal button is pressed. But looks like the form is always validated once and then when I click the button again the onclick on the button is executed. How do I prevent this?
I replicated the same issue with same form. For example if you go to http://redux-form.com/6.4.3/examples/syncValidation/ ,enter 4 in the age field and click on clear values. First time the validation triggers and stops the button action. Second time the button action works i.e, the form values are cleared..

The example you link to has that behavior because by default Redux Form will call the validation function for touched Fields on a blur event. The fact that you are clicking a button is irrelevant - you could click on any element or anywhere on the page and you would get that behavior.
The only real way to stop this behavior is to stop Redux Form from touching your Fields on a blur event. You can do this by setting touchOnBlur to false in the Redux Form config object.
export default reduxForm({ form: 'myForm', touchOnBlur: false })(MyForm);

Please Add type="button" to prevent the button from submitting the form.If you don't give any type it will consider submit.

Related

Custom button for record edit form

I have used a custom button to submit the updated record on LWC, used as quick action. In onclick funtion, I have used "this.template.querySelector('lightning-record-edit-form').submit(this.totalFieldList);" But when I submit the the values are still referred to the old values. Please help me on this.

How submit button works without `type="submit"`

I'm checking this example in react-hook-form doc: https://codesandbox.io/s/react-hook-form-v6-controller-qsd8r?file=/src/index.js
Weird thing is that the button doesn't have type="submit". But it still triggers submit event after clicking. (Screenshot attached below.)
How does it know which button is the submit button?
If a button is inside a form, then by default it is given the submit type, unless you give it another type.
So the Reset button in that codesandbox has type="button" to prevent it triggering the event, but the Submit button leaves it blank, so it submits by default.
Reference: Moz Docs

Disable submit button redux forms

How to disable submit button until all fields are filled in in reactjs with redux-forms.
To be more specific i have a form that consists only from radio buttons. So for every question there is 5 radio buttons to choose from. And i want by submit button to be disabled until all question are answered.
You need to leverage sync validation as shown here https://redux-form.com/6.6.3/examples/syncvalidation/ this will validate whole form if it's valid and pass necessary props to the component https://redux-form.com/6.6.3/docs/api/props.md/
invalid, valid
Then you can just bind disabled={invalid}
I created a sandbox to better illustrate it

With redux-form v7.2.0, how to autoSubmit on radio button selection?

I have a redux-form which has one field which asks the user to make a radio button selection. Once the user selects a radio button, I want the form to instantly-submit without the user having to click the submit button.
What is the correct way to auto-submit a form using redux-form v7.2.0?
In the radio onChange on onBlur callback you could setup a dispatch in the same way as remote submit is done: https://redux-form.com/7.3.0/examples/remotesubmit/

How to disable a React button conditionally on a state value?

I've added a simple form with one input and a save button. The save function is called and works as expected.
But I now want to add a boolean to disabled logic on the save button. So in my current page I have a state called email which I want to disable the button if this is empty.
What I did try is the following, passing {!this.state.email} into the disabled property of the button but it doesn't disable the save button. Similar to this example:
<Button primary={true} disabled={!this.state.email} onClick={this._onSave}>Save</Button>
I also logged the value in the _onBlur method and I can see that email state is being populated.
Question:
How can you bind component state to button disabled property?
This is a gist of my current component:
http://hastebin.com/jufahijoza.js
Look at my comments for an explanation.
_onBlur(event) {
//if(true or false)
// this.refs.myInputButton theres your button now disable/enable it with javascript
this.props.setUserEmail(event.target.value);
console.log(this.state.email);
}

Resources