1.1.11 • Published 4 years ago

react-native-basic-form v1.1.11

Weekly downloads
45
License
ISC
Repository
-
Last release
4 years ago

React Native Basic Form

A simple React Native Form component with TextInput (including multiline), DropDown and Image fields.",

Installation

$ npm install --save react-native-basic-form

#dependencies (Reat Native CLI only < v0.16)
npm i --save react-native-vector-icons  
react-native link react-native-vector-icon

Dependencies Setup (for Expo projects)

expo install @react-native-community/datetimepicker

Form

Shows a form

import React from 'react';
import {View} from 'react-native';
import Form, {TYPES} from 'react-native-basic-form';

export default function Example(props) {
    const [loading, setLoading] = useState(false);

    const options = [
        {label:"Basic", value:1},
        {label:"Premium", value:2}
    ];
    
    //Used in EDIT MODE
    const initialData = {
        "image": "http://res.cloudinary.com/ddv9bxonm/image/upload/v1585512850/ib9c0dml4dlksi8xgvob.jpg"
        "email": "Johnsmith@yahoo.com",
        "password": "thispasswordisencrypted",
        "account_type": 1, //Basic account, see options
        "price": 20,
        "about_me": "Blah blah blah.....",
        "start_date": "2020-04-17T21:00:00.000Z",
        "end_date": "2020-04-17T21:00:00.000Z",
    };

    const fields = [
        {name: 'image', label: 'Profile Image', required: true, type: TYPES.Image},
        {name: 'email', label: 'Email Address', required: true, type: TYPES.Email},
        {name: 'username', label: 'Username', required: true, autoCapitalize: "none", autoCorrect: false},
        {name: 'password', label: 'Password', required: true, secure: true},
        {name: 'account_type', label: 'Account Type', required: true, type: TYPES.Dropdown, options: options},
        {name: 'price', label: 'ENTRANCE FEE', required: true, type:TYPES.Number},
        {name: 'about_me', label: 'About Me', required: true, multiline: true},
        [
            //group to appear side by side
            {name: 'start_date', label: 'START DATE', required: true, type: TYPES.Date},
            {name: 'end_date', label: 'END DATE', required: true, type: TYPES.Date}
        ]
    ];

    async function onSubmit(data) {
        setLoading(true);

        console.log(data)
        ....
    }
    
    async function showImagePicker() {
        try{
            //return - cancelled or error or uri
            //return {cancelled:true}
            //return {error:"error message}
            //return {uri:...}
        }catch(e){
            return {error:e}
        }
    }

    render() {
        return (
            <View>
                <Form
                    title={"Register"} //this is the button title
                    fields={fields}
                    initialData={initialData} //used in edit mode
                    onSubmit={onSubmit}
                    loading={loading}
                    showImagePicker={showImagePicker}
                    style={{}}/>
            </View>
        );
    };
};

Field Types

TypeNotes
TextDefault
Number
Dropdown
Image
EmailSets the keyboard to display email-address type

Field Props

PropValueRequired/OptionalDescriptionDefault
namestringoptionalThe field title""
labelstringoptionalThe field label""
requiredbooloptionalWhether the field is requiredfalse
securebooloptionalWhether the value should be maskedfalse
typestringoptionalThe field typeTYPES.Text (see above)
autoCapitalizestringoptionalThe field auto capitalize setting"sentences"
autoCorrectbooloptionalThe field auto correct settingtrue
clearButtonModebooloptionalWhen the clear button should appear on the right side of the text view.never
editablebooloptionalIf false, text is not editable.true

Props

propvaluerequired/optionaldescriptiondefault
titlestringoptionalThe button title"Submit"
fieldsobjectrequiredthe fields to show[]
initialDataobjectoptionthe initial data, can be used in EDIT mode, the keys should match the fields key[]
onSubmitfunctionrequiredthe function to call when the submit button is pressednull
showImagePickerfunctionoptionalthe function to call when the image is tappednull
loadingbooleanoptionalif true, button is disabled and shows a loading iconfalse
styleobjectoptionalthe style for the container{}
buttonStyleobjectoptionalthe style for the button{}
keyboardShouldPersistTapsstringoptionalDetermines when the keyboard should stay visible after a tap.'handled'

keyboardShouldPersistTaps:https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago