Skip to content
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

Pull request #28

Open
wants to merge 45 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a119faa
Solved dependency issue
Jul 12, 2017
9dc8033
Added props support in custom components
Sep 22, 2017
7691c93
Merge branch 'master' of https://github.com/bietkul/react-native-form…
Sep 22, 2017
2b3d837
Added version 1.0.8
Sep 22, 2017
ec30c08
Update README.md
Sep 22, 2017
3d60069
Minor Fixes
Sep 22, 2017
b34b57b
Added ScrollViewProps
Sep 22, 2017
b331042
Update README.md
Sep 22, 2017
667d663
Added Custom Error Component
Sep 25, 2017
6c66781
Vesrion Update
Sep 25, 2017
c837376
Merge branch 'master' of https://github.com/bietkul/react-native-form…
Sep 25, 2017
65c8cd2
Added Customization For Error Icon
Sep 25, 2017
803d47e
Update README.md
Sep 25, 2017
3056612
Update README.md
Sep 27, 2017
4548964
Allow grouping of custom components
tristan-secord Oct 11, 2017
5088ed4
Merge pull request #5 from tristan-secord/groupCustomComponents
Oct 11, 2017
9f771b0
version update
Oct 11, 2017
4cbb020
Applying codemod to remove React.PropTypes
alterx Jan 31, 2018
e640692
Updating react versions
alterx Jan 31, 2018
d8f6068
Merge pull request #9 from alterx/master
Jan 31, 2018
6cb54b2
Update package.json
Jan 31, 2018
ed72161
Update README.md
Mar 28, 2018
4155d2f
Improve react-native-keyboard-aware-scroll-view
null-none Apr 23, 2018
394a86f
Merge pull request #13 from null-none/master
Apr 23, 2018
7ee827e
Update package.json
Apr 23, 2018
b25d7d6
Update README.md
Apr 23, 2018
bfad42e
Remove missing 'color' module that made build fail
infostreams May 10, 2018
be25064
Merge pull request #15 from infostreams/patch-1
May 14, 2018
888aa9f
Combined `styles.pickerMainAndroid` and the inline stylesheet using s…
markterence May 22, 2018
4bf0d1c
Merge pull request #17 from markterence/fix_picker_bgcolor_style_issue
May 26, 2018
34ba453
1.0.15
Jun 6, 2018
af82ed5
Add possibility to update Form fields (hidden, options, ...)
luissmg Nov 9, 2018
51dd411
Fix wrong variable name in getFieldValue
luissmg Nov 9, 2018
0ff4cf2
Fix setting values with setValues
luissmg Nov 12, 2018
4576d82
Merge pull request #25 from luissmg/master
bietkul Nov 21, 2018
8439dd1
release 1.0.16
bietkul Nov 21, 2018
a1da51d
Added missing quote
akshay11298 Feb 18, 2019
4ea4e7e
Merge pull request #33 from akshay11298/patch-1
bietkul Feb 18, 2019
5eb77f5
icon color change works with this
omer-waheed Mar 14, 2019
0e92a1f
Merge pull request #34 from omer-waheed/patch-1
bietkul Mar 15, 2019
1539d17
Installation instruction updated
irohitb Jun 20, 2019
358a0fa
Merge pull request #36 from irohitb/patch-1
bietkul Jun 20, 2019
e2a11f6
Delete package-lock.json
cludy-me Jul 4, 2019
509fff7
Update package.json
cludy-me Jul 4, 2019
05fce48
Merge pull request #39 from cludy-me/master
bietkul Sep 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[![NPM Version](https://img.shields.io/npm/v/react-native-form-builder.svg?style=flat)](https://www.npmjs.com/package/react-native-form-builder)
# react-native-form-builder
![alt text](http://g.recordit.co/7PqX8Ft7VO.gif)
![alt text](http://g.recordit.co/RWFvqi5tXG.gif)
# Note:
If you're looking for a better form management library with more advanced features, Please check out [React Reactive Form](https://github.com/bietkul/react-reactive-form).
## Features
- Generate Form Fields UI
- Manage, track state & values of fields
- Automatically manages focus to next field on submit (TextInput)
- Handle all keyboard related problems smartly
- Supports custom validations & nested forms
- Uses Nativebase components
- Uses <a href="https://github.com/GeekyAnts/NativeBase">Nativebase</a> components

## Getting Started

Expand All @@ -30,10 +33,26 @@
+ [Add Custom Validations](#add-custom-validations)
+ [Customize Your Form](#customize-your-form)
+ [Add custom components](#add-custom-components)
+ [Add custome error component](#add-custom-error-component)
- [Example](#example)

## Installation

`react-native-form-builder` requires a peer of [`native-base`](https://github.com/GeekyAnts/NativeBase)


To Install the peer dependecy
```
$ npm i native-base --save

```
link the peer dependecy using

```
react-native link
```
and then insteall `react-native-form-builder`

```bash
$ npm i react-native-form-builder --save
```
Expand Down Expand Up @@ -133,6 +152,8 @@ AppRegistry.registerComponent('FormGenerator', () => FormGenerator);
| customComponents | N/A | `object` | To define your custom type of components.|
| formData | N/A | `object` | To prefill the form values.|
| fields | `required` | `array` | Array of form fields. |
| scrollViewProps | N/A | `object` | Scrollview custom props. |
| errorComponent | N/A | `React Component` | Custom error display component. |

### Methods:
Currently, these methods are available in FormBuilder, you can access them by using ref property.
Expand Down Expand Up @@ -264,7 +285,7 @@ If you're using array of objects then please don't forget to define these proper
```jsx
objectType: true,
labelKey: 'name', // For Below example
primaryKey: 'id, // For Below example
primaryKey: 'id', // For Below example
```
For e.g.
```
Expand Down Expand Up @@ -395,12 +416,13 @@ Build your custom type's components & handle them easily with the help of form b
Use the `customComponents` prop of form builder.
### Prototype
It's an object of key value pair where key will be the `type` of the component & value will be your custom Component.<br/><br/>
```customComponents = { type1: ComponentName1, type2: ComponentName2 .....}```
```customComponents = { type1: {component: ComponentName1, props: Props }, type2: {component: ComponentName2} .....}```

### How To Use
- Define your custom `type` in field's object.
- Form builder extends the props of your component by adding some extra props.
- In you component you can access these props to handle the state of the field.
- You can also pass some extra props in your custom components.
- In your component you can access these props to handle the state of the field.

| Props | Type | Description |
| :------------| :------| :-----|
Expand All @@ -409,6 +431,10 @@ It's an object of key value pair where key will be the `type` of the component &
| onSummitTextInput(fieldName) | `function`| If you're using TextInput then you can use this function to automatically manage the text input focus.For example you can define it in the `onSubmitEditing` prop of TextInput
| theme | `object` | Use the theme variables to style your component

## Add Custom Error Component
- Now you can use your custom error component to display error messages.
- In your custom component you will receive two props `attributes` & `theme` variables.
- You can access the error & error message as a property of the attributes object.


## Example
Expand Down
62 changes: 34 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name":"react-native-form-builder",
"version":"1.0.5",
"description":"Generate Awesome Forms In an easy way",
"main":"src/index.js",
"scripts":{
"test":"echo \"Error: no test specified\" && exit 1"
"name": "react-native-form-builder",
"version": "1.0.16",
"description": "Generate Awesome Forms In an easy way",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository":{
"type":"git",
"url":"git+https://github.com/bietkul/react-native-form-builder.git"
"repository": {
"type": "git",
"url": "git+https://github.com/bietkul/react-native-form-builder.git"
},
"_npmUser":{
"name":"anjuma",
"email":"kuldepsaxena@155@gmail.com"
"_npmUser": {
"name": "anjuma",
"email": "kuldepsaxena@155@gmail.com"
},
"author":"Kuldeep Saxena",
"license":"MIT",
"bugs":{
"url":"https://github.com/bietkul/react-native-form-builder/issues"
"author": "Kuldeep Saxena",
"license": "MIT",
"bugs": {
"url": "https://github.com/bietkul/react-native-form-builder/issues"
},
"homepage":"https://github.com/bietkul/react-native-form-builder#readme",
"keywords":[
"homepage": "https://github.com/bietkul/react-native-form-builder#readme",
"keywords": [
"android",
"ios",
"react",
Expand All @@ -32,16 +32,22 @@
"generator",
"builder"
],
"dependencies":{
"fs-extra":"^3.0.1",
"print-message":"^2.1.0",
"lodash":"^4.17.4",
"react-native-keyboard-aware-scroll-view":"^0.2.7",
"react-native-i18n":"^1.0.0"
"dependencies": {
"fs-extra": "^3.0.1",
"lodash": "^4.17.4",
"print-message": "^2.1.0",
"prop-types": "^15.6.0",
"react-native-i18n": "^2.0.0",
"react-native-keyboard-aware-scroll-view": "^0.8.0"
},
"devDependencies":{
"react":"15.4.2",
"react-native":"0.41.1",
"native-base":"^2.0.6"
"devDependencies": {
"native-base": "^2.12.0",
"react": "^16.8.0",
"react-native": "0.60.0"
},
"peerDependencies": {
"react-native": ">=0.60.0",
"react": ">=15.5.0",
"native-base": "^2.12.0"
}
}
5 changes: 3 additions & 2 deletions src/components/panel/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Animated, Dimensions, View, Easing, Keyboard } from 'react-native';
import styles from './styles';

class Panel extends Component {

static propTypes = {
children: React.PropTypes.object,
children: PropTypes.object,
}

constructor(props) {
Expand Down Expand Up @@ -55,4 +56,4 @@ class Panel extends Component {
);
}
}
export default Panel;
export default Panel;
20 changes: 11 additions & 9 deletions src/fields/date/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { View, Text } from 'native-base';
import I18n from 'react-native-i18n';
Expand All @@ -9,10 +10,11 @@ export default class DatePickerField extends Component {
timeZoneOffsetInHours: (-1) * ((new Date()).getTimezoneOffset() / 60),
};
static propTypes = {
attributes: React.PropTypes.object,
updateValue: React.PropTypes.func,
timeZoneOffsetInHours: React.PropTypes.number,
theme: React.PropTypes.object,
attributes: PropTypes.object,
updateValue: PropTypes.func,
timeZoneOffsetInHours: PropTypes.number,
theme: PropTypes.object,
ErrorComponent: PropTypes.func,
}
constructor(props) {
super(props);
Expand Down Expand Up @@ -69,7 +71,7 @@ export default class DatePickerField extends Component {
}
};
render() {
const { theme, attributes } = this.props;
const { theme, attributes, ErrorComponent } = this.props;
const value = (attributes.value && new Date(attributes.value)) || null;
const mode = attributes.mode || 'datetime';
return (
Expand Down Expand Up @@ -132,6 +134,7 @@ export default class DatePickerField extends Component {
}
</View>
</TouchableOpacity>
<ErrorComponent {...{ attributes, theme }} />
<Panel
ref={(c) => { this.panel = c; }}
>
Expand Down Expand Up @@ -196,11 +199,10 @@ export default class DatePickerField extends Component {
</TouchableOpacity>
}
</View>
<ErrorComponent {...{ attributes, theme }} />
</TouchableOpacity>

}
}
</View>

);
}
}
}
16 changes: 10 additions & 6 deletions src/fields/form/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { View, Text } from 'native-base';
import GenerateForm from '../../formBuilder';

export default class FormField extends Component {
static propTypes = {
attributes: React.PropTypes.object,
theme: React.PropTypes.object,
updateValue: React.PropTypes.func,
autoValidation: React.PropTypes.bool,
customValidation: React.PropTypes.func,
attributes: PropTypes.object,
theme: PropTypes.object,
updateValue: PropTypes.func,
autoValidation: PropTypes.bool,
customValidation: PropTypes.func,
customComponents: PropTypes.object,
}
constructor(props) {
super(props);
Expand All @@ -31,6 +33,7 @@ export default class FormField extends Component {
theme,
autoValidation,
customValidation,
customComponents,
} = this.props;
return (
<View>
Expand All @@ -43,6 +46,7 @@ export default class FormField extends Component {
onValueChange={this.onValueChange}
autoValidation={autoValidation}
customValidation={customValidation}
customComponents={customComponents}
showErrors
fields={attributes.fields}
theme={theme}
Expand All @@ -51,4 +55,4 @@ export default class FormField extends Component {
</View>
);
}
}
}
21 changes: 12 additions & 9 deletions src/fields/picker/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { View, Text } from 'native-base';
import { Platform, Picker, TouchableOpacity } from 'react-native';
Expand All @@ -7,26 +8,27 @@ import styles from './../../styles';
const Item = Picker.Item;
export default class PickerField extends Component {
static propTypes = {
attributes: React.PropTypes.object,
theme: React.PropTypes.object,
updateValue: React.PropTypes.func,
attributes: PropTypes.object,
theme: PropTypes.object,
updateValue: PropTypes.func,
ErrorComponent: PropTypes.func,
}
handleChange(value) {
const attributes = this.props.attributes;
this.props.updateValue(attributes.name, attributes.options[value]);
}
render() {
const { theme, attributes } = this.props;
const { theme, attributes, ErrorComponent } = this.props;
const isValueValid = attributes.options.indexOf(attributes.value) > -1;
const pickerValue = attributes.options.indexOf(attributes.value).toString();
if (Platform.OS !== 'ios') {
return (
<View
style={Object.assign(styles.pickerMainAndroid, {
style={{...styles.pickerMainAndroid, ...{
backgroundColor: theme.pickerBgColor,
borderBottomColor: theme.inputBorderColor,
borderBottomWidth: theme.borderWidth,
})}
}}}
>
<View style={{ flex: 7 }}>
<Text style={{ color: theme.inputColorPlaceholder }}>{attributes.label}</Text>
Expand All @@ -42,12 +44,12 @@ export default class PickerField extends Component {
>{
attributes.options.map((item, index) => (
<Item key={index} label={item} value={`${index}`} />
))
))
}
</Picker>
</View>
<ErrorComponent {...{ attributes, theme }} />
</View>

);
}
return (
Expand Down Expand Up @@ -75,6 +77,7 @@ export default class PickerField extends Component {
{isValueValid ? attributes.value : 'None'}
</Text>
</TouchableOpacity>
<ErrorComponent {...{ attributes, theme }} />
<View style={{ flex: 1 }}>
<Panel
ref={(c) => { this.panel = c; }}
Expand All @@ -97,4 +100,4 @@ export default class PickerField extends Component {

);
}
}
}
Loading