Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-native-formx
Advanced tools
Readme
⚛️ 📃 React Native custom form builder with support for plain form, tabs and step-by-step.
npm i react-native-formx
react-native link react-native-gesture-handler
react-native link react-native-reanimated
react-native link react-native-tab-view
See examples/RNFormsPlayground
for examples that you can play with.
Plain Form | Step by step | Tabs |
---|---|---|
Name | Usage |
---|---|
Form | Form is the root component of the tree. It will render the internal form tree and will make avaiable the handlers for your component. |
FormView | FormView is where all your fields will be really rendered. This is basically a View with all the fields(which are another components) rendered inside and some extra methods to handle internal submits/clears/validations events. |
FormTabs | FormTabs is a manager for FormTab components. |
FormTab | Imagine FormTab as a simple View rendered inside the FormTabs manager. Inside it will be displayed a FormView component where the fields will be rendered. |
FormSteps | FormSteps is a amnager for FormStep components. |
FormStep | Imagine FormStep as a simple View rendered inside the FormSteps manager. Inside it will be displayed a FormView component where the fields will be rendered. FormStep will contain specific step-by-step buttons like Back and Next Step . |
import { Form } from 'react-native-formx';
const MyComponent = props => (
<Form>
/* Rendering as plain form */
<FormView>
{fields}
</FormView>
/* Rendering as tabs */
<FormTabs>
<FormTab title="Tab 1">
{fields}
</FormTab>
<FormTab title="Tab 2">
{fields}
</FormTab>
</FormTabs>
/* Rendering as step-by-step */
<FormSteps backButtonText="Go Back">
<FormStep title="Step 1">
{fields}
</FormStep>
<FormStep title="Step 2">
{fields}
</FormStep>
</FormSteps>
</Form>
);
You can render a form using only a .js
configuration. In that cases the root Form component will automatically render based on props.
// withViewProps.js
const withViewProps = {
fields: [
// list of fields
],
};
export default withViewProps;
// withTabProps.js
const withTabProps = {
tabIndicatorColor: 'white',
tabTintColor: 'purple',
tabTextColor: 'white',
tabs: [
{
title: 'Tab 1',
fields: [
// list of fields
]
},
{
title: 'Tab 2',
fields: [
// list of fields
],
},
],
};
export default withTabProps;
// withStepProps.js
const withStepProps = {
indicatorColor: 'purple',
buttonTintColor: 'purple',
buttonTextColor: 'white',
backButtonTextColor: 'purple',
nextStepButtonText: 'Next Step',
backButtonText: 'Go Back',
steps: [
{
title: 'Step 1',
fields: [
// list of fields
],
},
{
title: 'Step 2',
fields: [
// list of fields
],
},
{
title: 'Step 3',
fields: [
// list of fields
],
},
],
};
export default withStepProps;
then...
import { Form } from 'react-native-formx';
import withViewProps from './withViewProps';
const MyComponent = props => (
<Form {...withViewProps} />
);
Name | Description | Support |
---|---|---|
submit | Manually submits the form. The form data will be avaiable on the onSubmit handler. | * |
clear | Manually clears the form. | FormView, FormTabs |
Name | Description |
---|---|
onSubmit | Called after button of submit type pressed or manual call to submit public method. |
onInvalid | Called when user tries to submit or request a new step and any of the active FormView fields have invalid values. The field payload will be defined as the first argument on this callback. |
const handleSubmitForm = formData => console.log(formData);
const handleInvalidForm = field => {
console.log(`Form "${field}" field got invalid value.`);
};
<Form
{...props}
onSubmit={handleSubmitForm}
onInvalid={handleInvalidForm}
/>
List of acceptable props for containers components.
Name | Type |
---|---|
title | String |
backButtonText | String |
nextStepButtonText | String |
buttonTintColor | Color |
buttonTextColor | Color |
submitButtonText | String |
Name | Type |
---|---|
tabTintColor | Color |
tabTextColor | Color |
tabIndicatorColor | Color |
Renders a clear button alongside the FormView content. This will automatically call the clear form method from inside it.
Prop | Type |
---|---|
title | String |
buttonTintColor | Color |
buttonTextColor | Color |
Refers to this field using clear
field type when rendering from props.
Renders a react-native-text-input-mask text input component.
Prop | Type |
---|---|
name | String |
title | String |
maskType | String |
validators | String |
See react-native-text-input-mask for more avaiable props.
Refers to this field using masked
field type when rendering from props.
Renders a react-native-modal-select-list component.
Prop | Type |
---|---|
name | String |
title | String |
required | Boolean |
options | Array[react-native-modal-select-list] |
Refers to this field using option
field type when rendering from props.
Renders a radio button with a list of options.
Prop | Type |
---|---|
name | String |
title | String |
options | Array[{ label: String, value: any }] |
Refers to this field using radio
field type when rendering from props.
Renders a submit button alongside the FormView content. This will automatically call the submit form method from inside it.
Prop | Type |
---|---|
title | String |
buttonTintColor | Color |
buttonTextColor | Color |
Refers to this field using submit
field type when rendering from props.
Renders a React Native Switch component.
Prop | Type |
---|---|
name | String |
title | String |
activeColor | Color |
Refers to this field using switch
field type when rendering from props.
Renders a plain React Native TextInput component.
Prop | Type |
---|---|
title | String |
name | String |
required | Boolean |
validators | String |
Refers to this field using text
field type when rendering from props.
Note: All the name
are required at the runtime. This prop will be used to save the value from the form field inside the resumed form data object.
When using the form in step-by-step mode you can dynamically show some fields based on previous steps fields values. Declare a show
function into the fields props. It will receive the actual formData within all inputed fields values until there. Return a boolean that tells if this field must be rendered and visible into the active FormView.
Example:
{
name: 'myField',
type: 'text',
show: ({ anotherFieldValue }) => anotherFieldValue === 'abc',
}
Note: If field is not rendered by the FormView and user submit it will not be defined into the final submit form data.
There are some default supported masks that can be displayed when using MaskedTextInput
with the default maskType
prop.
See react-native-text-input-mask for reference.
You can use the following common validators as validator
prop for TextInput
and MaskedTextInput
fields:
email
,
cpf
,
cnpj
,
phone
,
br-cellphone
FAQs
⚛️ 📃 React Native custom form builder with support for plain form, tabs and step-by-step
The npm package react-native-formx receives a total of 1 weekly downloads. As such, react-native-formx popularity was classified as not popular.
We found that react-native-formx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.