1.0.5 • Published 4 years ago

rn-easy-forms v1.0.5

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

React Native Easy Forms

This module allows you to create React Native forms by declaring your form as a Javascript object.

Features

  • Automatically validates fields for being empty or not
  • Supports auto-completion
  • Support auto completing places using Google Places Autocomplete API
  • Supports displaying a checkbox for toggling the display of secure text fields
  • Fully customizable appearance

Usage

yarn add rn-easy-forms
npm i --save rn-easy-forms

Example

import { Form } from 'rn-easy-forms'
import { View, Button } from 'react-native'

const signInFields = [
  {
    name: EMAIL_FIELD_NAME,
    placeholder: EMAIL_PLACEHOLDER
  },
  {
    name: PASSWORD_FIELD_NAME,
    placeholder: PASSWORD_PLACEHOLDER,
    secure: true
}]

class SignInForm extends React.Component {
  _signInAsync = async () => {
    let  validateResult  =  this.formRef.validate()
    if (validateResult) {
      //proceed to next page
    }
  }

  render() {
    return (
      <View>
      <Form
        ref={(el) => {this.formRef = el}}
        fieldList={signInFields}
      />
      <Button title="Sign In" onPress={this._signInAsync}  />
      </View>
    )
  }
}

Usage

Props

NameTypeDescriptionRequired
fieldListArray\<Object>Array of objects describing each field in the formY
suggestionProvidersObjectKey value pairs of String -> SuggestionProviderN
fieldWithCheckboxStyleObjectStyles for the container holding a field and a secure text entry checkboxN

Spec

Field Object Keys

KeyValueDescriptionRequired
nameStringunique name of the fieldY
placeholderStringplaceholder for field inputN
autocompleteTypeStringtype of SuggestionProvider to use, a key with this SuggestionProvider must exist in the suggestionProviders prop passed to the formN
additionalDataForSuggestionsProviderObjectadditional data used by the SuggestionsProvider for providing autocomplete suggestionsN
allowEmptyBooleanallows the field to be empty, default is falseN
secureBooleanmakes the text entry secureN
showSecureCheckboxBooleanif set, a checkbox will be displayed below the field toggling the display between hidden and plain textN
keyboardTypeStringset the keyboard type of the fieldN

Suggestion Providers Example

{ "Google" : new GoogleSuggestionProvider("YOUR_API_KEY") }

For custom suggestion providers, your class can use have these methods(Typescript interface coming soon):

Methodargsdescriptionrequired
async getSuggestionsinput(String), sessionToken(String), additionalData(Object)fetches autocomplete suggestions. uses an optional sessionToken, used to group autocomplete requests and accepts an arbitrary object defining any additional data used for the autocomplete requestY
async onSelectSuggestionitem(Object), setAdditionalFields(Function), additionalData(Object), sessionToken(String)Additional logic to be executed when an autocomplete suggestion is selectedN
renderFooterreturns a footer component to render at the bottom of the autocomplete suggestionsN

API

Methodargsdescriptionreturn type
validatevalidates the form, returns undefined if validation fails or an Object with key value pairs of {name: value} where the name is the unique name for the fieldObject