GithubHelp home page GithubHelp logo

esbenp / react-native-redux-form-example Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 4.0 127 KB

Code for http://esbenp.github.io/2017/01/06/react-native-redux-form-immutable-styled-components/

JavaScript 40.86% Python 13.03% Java 11.14% Objective-C 34.97%

react-native-redux-form-example's People

Contributors

esbenp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-redux-form-example's Issues

Not hitting dispatching submit function

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="[email protected]" />
        <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

handleSubmit function not getting values

Since you provided only react-form example with react-native, I want to ask you this question. My application uses React-native, Redux, Redux-navigation and Redux-persist.
"react": "16.0.0", "react-native": "0.50.1", "react-native-vector-icons": "^4.4.2", "react-navigation": "^1.0.0-beta.19", "react-redux": "^5.0.6", "redux": "^3.7.2", "redux-form": "^7.2.0", "redux-logger": "^3.0.6", "redux-persist": "^5.2.2", "redux-thunk": "^2.2.0"

It is a simple login screen. Even all values entered are in the redux store, handleSubmit function gets empty object.

SigninFormView.js


import React from 'react'
import { connect } from 'react-redux'
import { Field,reduxForm, formValueSelector, getFormValues, getFormMeta} from 'redux-form'
import { StyleSheet,View,Text,TextInput,TouchableOpacity } from 'react-native'

const  = (props) => {
  const {input} = props
  return (
   <View>
      <TextInput style={styles.input}
            {...props}
            onChangeText={input.onChange}
            onBlur={input.onBlur}
            onFocus={input.onFocus}
             />
    </View>
  )
}

const SigninFormView = props => {
  const { handleSubmit,validate, pristine, reset, submitting } = props
  return (
    <View style={styles.container}>
          <Field name="email" type="email" autoCapitalize="none" autoCorrect={false} keyboardType='email-address' placeholder='Your email' component={} label="Email" />
          <Field name="password" type="password" autoCapitalize="none" autoCorrect={false} secureTextEntry={true} placeholder='Password' component={} label="Password" />
          <TouchableOpacity disabled={pristine || submitting} onPress={handleSubmit}>
            <Text style={styles.button}>Sign In</Text>
          </TouchableOpacity>
    </View>
  )
}

SigninFormView = reduxForm({
  form: 'SignInForm',
})(SigninFormView)

export default SigninFormView

SigninScreen.js


import React from 'react';
import { connect } from 'react-redux'
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';
import SigninFormView from '../components/SigninFormView'

const showResults = (values) => {
   return new Promise((resolve) => {
    setTimeout(() => {
      console.log('showResults:',values)
      resolve()
    }, 500)
  })
}

const SigninScreen = ({ navigation }) => (
  <View style={styles.container}>
    <SigninFormView onSubmit={showResults}/>
  </View>
);

SigninScreen.propTypes = {
  navigation: PropTypes.object.isRequired,
};

Here is redux log. You can see the store has "form" and all the entered values are in the store.

image

Any idea what might be the problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.