esbenp / react-native-redux-form-example

Code for http://esbenp.github.io/2017/01/06/react-native-redux-form-immutable-styled-components/
22 stars 4 forks source link

Not hitting dispatching submit function #2

Open The-Code-Monkey opened 6 years ago

The-Code-Monkey commented 6 years ago

So i have copied your example and linked it up to an api endpoint which should error due to not being authenticated but its not seeming to get to the action.

`import { submitForm } from '../../reducers/audits';

const onSubmit = (values) => { console.warn(values); submitForm(values); }; const countryOptions = [ { label: 'Denmark', value: 'DK' }, { label: 'Germany', value: 'DE' }, { label: 'United State', value: 'US' }, ];

class Audit extends Component { render() { const { handleSubmit, submitting } = this.props;

return (
  <Form>
    <FieldsContainer>
      <Fieldset label="Contact details">
        <Input name="first_name" label="First name" placeholder="John" />
        <Input name="last_name" label="Last name" placeholder="Doe" />
        <Input name="email" label="Email" placeholder="something@domain.com" />
        <Input name="telephone" label="Phone" placeholder="+45 88 88 88 88" />
      </Fieldset>
      <Fieldset label="Shipping details" last>
        <Input name="address" label="Address" placeholder="Hejrevej 33" />
        <Input name="city" label="City" placeholder="Copenhagen" />
        <Input name="zip" label="ZIP Code" placeholder="2400" />
        <Select
          name="country"
          label="Country"
          options={countryOptions}
          placeholder="Denmark"
        />
        <Switch label="Save my details" border={false} name="save_details" />
      </Fieldset>
    </FieldsContainer>
    <ActionsContainer>
      <Button icon="md-checkmark" iconPlacement="right" onPress={handleSubmit(onSubmit)} submitting={submitting}>Save</Button>
    </ActionsContainer>
  </Form>
);

} }

export default reduxForm({ form: 'Form', validate: (values) => { const errors = {};

if (!values.first_name) {
  errors.first_name = 'First name is required.';
}

if (!values.last_name) {
  errors.last_name = 'Last name is required.';
}

if (!values.email) {
  errors.email = 'Email is required.';
}

return errors;

}, })(Audit);`

this is all my code im not sure where im going wrong as that console warn will warn me with the object with my field values in it but some reason it wont hit the submitForm from my reducer.

I am new to react-native I am normally a reactjs dev

romeo-folie commented 6 years ago

Did you ever get a fix for this? Cos I have the same issue too.

The-Code-Monkey commented 6 years ago

can you make a gist of your code and ill see if its the same issue

romeo-folie commented 6 years ago

Never mind. Turns out it wasn't the same thing and I fixed mine. Appreciate your will to help though.