-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can you render html basic element ? #93
Comments
import { APP_NAME } from "@env";
import { Text, View } from "react-native";
import { connect } from "react-redux";
import { setError } from "../reducers/ScreenNotificationReducer";
import { useNavigation } from "@react-navigation/native";
import { theme } from "../styles/theme";
import { Validators, FormGenerator } from "react-reactive-form";
const Login = (props) => {
const navigation = useNavigation;
handleReset = () => {
this.loginForm.reset();
};
handleSubmit = (e) => {
e.preventDefault();
console.log("Form values", this.loginForm.value);
};
setForm = (form) => {
this.loginForm = form;
this.loginForm.meta = {
handleReset: this.handleReset,
};
};
return (
<View style={styles.centered}>
<Text>{APP_NAME}: This is the login view</Text>
{RenderLoginForm()}
</View>
);
};
const RenderLoginForm = () => {
return (
<form onSubmit={this.handleSubmit}>
<FormGenerator onMount={this.setForm} fieldConfig={fieldConfig} />
</form>
);
};
const TextInput = ({ handler, touched, hasError, meta }) => (
<div>
<input placeholder={`Enter ${meta.label}`} {...handler()} />
<span>
{touched && hasError("required") && `${meta.label} is required`}
</span>
</div>
);
// Checkbox component
const CheckBox = ({ handler }) => (
<div>
<input {...handler("checkbox")} />
</div>
);
// Field config to configure form
const fieldConfig = {
controls: {
username: {
options: {
validators: Validators.required,
},
render: TextInput,
meta: { label: "Username" },
},
password: {
options: {
validators: Validators.required,
},
render: TextInput,
meta: { label: "Password" },
},
rememberMe: {
render: CheckBox,
},
$field_0: {
isStatic: false,
render: ({ invalid, meta: { handleReset } }) => (
<Vi>
<button type="button" onClick={handleReset}>
Reset
</button>
<button type="submit" disabled={invalid}>
Submit
</button>
</Vi>
),
},
},
};
const mapDispatchToProps = {
setError,
};
const styles = {
...theme,
};
export default connect(null, mapDispatchToProps)(Login); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Invariant Violation: View config getter callback for component
input
must be a function (receivedundefined
). Make sure to start component names with a capital letter.The text was updated successfully, but these errors were encountered: