

InstallationThe peer dependencies included from any npm packages does not automatically get installed. Your application will not depend on it explicitly.
react-native-form4u requires a peer of native-base
Install NativeBase
npm install native-base --save
Link the library
react-native link native-base
If you have icons problems, please try to install and link react-native-vector-icons
npm install --save react-native-vector-icon
react-native link react-native-vector-icons
$ npm i react-native-form4u --save
Basic Usagenpm i -g react-native
Fields are array items. You can easily define more than one field per row. See example for more details.
| Prop | Description | Default |
|---|---|---|
name |
Field name | None |
label |
Field label | None |
required |
Required field | false |
type |
Field type | Field Types |
fieldProps |
Default react props for each field type | None |
defaultValue |
Default value for the field | None |
fieldStyle |
Style object for the field | None |
mask |
Custom mask for the field | None |
formFields = [
[
{
name: "field1",
label: "Field 1",
required: false,
type: "text",
fieldProps: {},
defaultValue: null,
fieldStyle: {},
mask: {}
}
]
];
Example:
const fields = [
[
{
name: "firstName",
label: "First Name",
type: "input",
inputProps: {
autoCorrect: false
}
},
{
name: "lastName",
label: "Last Name",
type: "input",
inputProps: {
autoCorrect: false
}
}
],
[
{
name: "email",
label: "Email",
type: "input",
inputProps: {
autoCorrect: false,
autoCapitalize: "none",
keyboardType: "email-address"
}
}
],
[
{
name: "subject",
placeholder: "Pick a topic of your interest",
pickerItems: [
{
label: "React Native",
value: 0
},
{
label: "React Hooks",
value: 1
},
{
label: "React Navigation",
value: 2
},
{
label: "React News",
value: 3
}
],
type: "picker"
}
],
[
{
name: "password",
label: "Password",
type: "input",
inputProps: {
secureTextEntry: true
}
}
],
[
{
name: "subscribe",
label: "Subscribe me to weekly news from Tech world.",
type: "boolean",
defaultValue: true
}
],
[
{
name: "signUpButton",
label: "Sign Up",
type: "button"
}
],
[
{
name: "resetButton",
label: "Reset",
type: "button"
}
]
];
const validate = ({ firstName, lastName, email, subject, password }) => {
const errors = {};
if (!firstName.value) {
errors.firstName = "First name is required";
}
if (!lastName.value) {
errors.lastName = "Last name is required";
}
if (!email.value) {
errors.email = "Email address is required";
} else if (!/\S+@\S+\.\S+/.test(email.value)) {
errors.email = "Email address is invalid";
}
if (!subject.value) {
errors.subject = "A subject of interest is required.";
}
if (!password.value) {
errors.password = "Password is required";
}
return errors;
};
export default validate;
const handleSubmit = fields => {
const { firstName, lastName, email, subject, password } = fields;
Alert.alert(
"Your info",
`First Name: ${firstName.value}\n Last Name: ${lastName.value}\n Email: ${
email.value
}\n Subject: ${subject.value} \n Password: ${password.value}`
);
};
Field TypesField will be automatically formated according to card provider:
9999 9999 9999 9999 or 9999 **** **** 9999 (obfuscated)9999 999999 99999 or 9999 ****** 99999 (obfuscated)9999 999999 9999 or 9999 ****** 9999 (obfuscated)Field will be automatically formated for 999.999.999-99
Field will be automatically formated for 99.999.999/9999-99
Field will be automatically formated for 99999-999
accept only numbers
PropertiesAny View property and the following:
| Prop | Description | Default |
|---|---|---|
formFields |
Object with field definitions. | None |
handleSubmit |
Callback function to handle form submission | Inherited |
validation |
Function to return errors object | {fieldName: error message} |
submitOnDirty |
Disable form buttons in case form is dirty (empty or with errors) | false |
formStyle |
Style object with custom styles. Overrides default style of the Form | {flex:1 , padding: 10} |
Most style properties will work as expected.
| Prop | Description | Default |
|---|---|---|
size |
Size of the icon, can also be passed as fontSize in the style object. |
12 |
name |
What icon to show, see Icon Explorer app or one of the links above. | None |
color |
Color of the icon. | Inherited |
If you want, we use the MaskService from react-native-masked-text
Form exampleimport Form4u from "react-native-form4u";
import fields from "./formFields.js";
import validationRules from "./formValidationRules.js";
const App = () => {
return (
<Form4u
formFieldsRows={fields}
handleSubmit={handleSubmit}
validation={validationRules}
submitOnDirty
/>
);
};
export default App;
BACKLOGVersion History0.0.1
ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License$ claude mcp add react-native-form4u \
-- python -m otcore.mcp_server <graph>