esbenp / react-native-redux-form-example Goto Github PK
View Code? Open in Web Editor NEWCode for http://esbenp.github.io/2017/01/06/react-native-redux-form-immutable-styled-components/
Code for http://esbenp.github.io/2017/01/06/react-native-redux-form-immutable-styled-components/
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
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.
Any idea what might be the problem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.