Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

LocalForm: valid & pending #1193

Open
jdmoliner opened this issue Nov 29, 2018 · 0 comments
Open

LocalForm: valid & pending #1193

jdmoliner opened this issue Nov 29, 2018 · 0 comments

Comments

@jdmoliner
Copy link

jdmoliner commented Nov 29, 2018

Hi,

I can't get to work at the same time valid and pending to disable a button. I need to disable button when form is not valid or is pending.

I have a code like this:

import React from 'react';
import {
  LocalForm,
  Control,
  actions
} from 'react-redux-form';

const validateMinAmount = (amount) => amount > 0;
const validateMaxAmount = (amount) => amount < 10000;

class MyForm extends React.Component {
  constructor(props) {
    super(props);    
  }

  attachDispatch(dispatch) {
    this.formDispatch = dispatch;
  }

  handleSubmit() {
     this.formDispatch(actions.setPending('myform',true));
     console.log("submit!");
  }

  render() {
    return (
      <LocalForm
        model="myform"
        getDispatch={(dispatch) => this.attachDispatch(dispatch)}
        initialState={{amount: ''}}
        onSubmit={(myform) => this.handleSubmit(myform)}
      >
        <Control.text
            type="number"
            model=".amount"                  
            validators={{
               validateMinAmount,
               validateMaxAmount
            }}
            step={0.01}                 
          />

        <Control.button
           type="submit"
           className="save"
           model="myform"
           disabled={{valid:false, pending:true}}  // with disabled={{valid:false}} or disabled={{valid:true}} works, but not at same time
         >
      </LocalForm>
    )
  }
}
@jdmoliner jdmoliner changed the title LocalForm & pending LocalForm: valid & pending Nov 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant