• Stars
    star
    479
  • Rank 91,752 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy react-native forms using bootstrap-like syntax with redux-form+immutablejs integration. Styled using styled-components

react-native-clean-form

npm Dependency Status devDependency Status

Easy react-native forms using bootstrap-like syntax with redux-form+immutablejs integration. Styled using styled-components

Big kudos to Artyom Khamitov

The look of the form was inspired by this shot by Artyom Khamitov. Check out his profile on Dribbble.

















Installation

Run npm install --save react-native-clean-form

The form uses react-native-vector-icons so it is important the fonts are linked by using react-native link or one of the other options available.

Example

I have written an article on my blog about React Native and redux-form

For a complete example check out the example folder

Usage

import {
  ActionsContainer,
  Button,
  FieldsContainer,
  Fieldset,
  Form,
  FormGroup,
  Input,
  Label,
  Switch
} from 'react-native-clean-form'

const FormView = props => (
  <Form>
    <FieldsContainer>
      <Fieldset label="Contact details">
        <FormGroup>
          <Label>First name</Label>
          <Input placeholder="Esben" onChangeText={this.onFirstNameChange} />
        </FormGroup>
        <FormGroup>
          <Label>Email</Label>
          <Input placeholder="[email protected]" onChangeText={this.onEmailChange} />
        </FormGroup>
      </Fieldset>
      <Fieldset label="Password" last>
        <FormGroup>
          <Label>Password</Label>
          <Input placeholder="Enter a password" onChangeText={this.onPasswordChange} />
        </FormGroup>
        <FormGroup>
          <Label>Repeat password</Label>
          <Input placeholder="Repeat your password" onChangeText={this.onRepeatPasswordChange} />
        </FormGroup>
        <FormGroup border={false}>
          <Label>Save my password</Label>
          <Switch onValueChange={this.toggleSaveMyPassword} />
        </FormGroup>     
      </Fieldset>
    </FieldsContainer>
    <ActionsContainer>
      <Button icon="md-checkmark" iconPlacement="right" onPress={this.save}>Save</Button>
    </ActionsContainer>
  </Form>
)

Usage with redux-form

import React from 'react'
import { reduxForm } from 'redux-form'
import {
  ActionsContainer,
  Button,
  FieldsContainer,
  Fieldset,
  Form,
  FormGroup,
  Label,
} from 'react-native-clean-form'
import {
  Input,
  Switch
} from 'react-native-clean-form/redux-form'
import { View,Text } from 'react-native'

const onSubmit = (values, dispatch) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(values)
      resolve()
    }, 1500)
  })
}

const FormView = props => {
  const { handleSubmit, submitting } = this.props

  return (
    <Form>
      <FieldsContainer>
        <Fieldset label="Contact details">
          <Input name="first_name" label="First name" placeholder="John" />
          <Input name="email" label="Email" placeholder="[email protected]" />
        </Fieldset>
        <Fieldset label="Shipping details" last>
          <Input name="password" label="Address" placeholder="Hejrevej 33" />
          <Input name="password_repeat" label="City" placeholder="Copenhagen" />
          <Switch label="Save my details" border={false} name="save_details" />
        </Fieldset>
      </FieldsContainer>
      <ActionsContainer>
        <Button icon="md-checkmark" iconPlacement="right" onPress={handleSubmit(onSubmit)} submitting={submitting}>Save</Button>
      </ActionsContainer>
    </Form>
  )
}

export default reduxForm({
  form: 'Form'
})(FormView)

Usage with redux-form and Immutable.js

To make it work with Immutable.js import Input, Select, and Switch from react-native-clean-form/redux-form-immutable instead of react-native-clean-form/redux-form. Also, check out the included example

Validation

If integrating with redux-form validation is supported right out of the box. Just add a validation key to reduxForm your normally would.

If not using redux-form, there is an error prop on FormGroup which will display the error if used.





Async feedback

The Button component has a submitting prop. If true, a spinner will be displayed.





Run the example

Clone the repo first.

git clone https://github.com/esbenp/react-native-clean-form && cd react-native-clean-form

Install dependencies.

cd example
npm install

Run the simulator.

react-native run-ios

More Repositories

1

pdf-bot

🤖 A Node queue API for generating PDFs using headless Chrome. Comes with a CLI, S3 storage and webhooks for notifying subscribers about generated PDFs
JavaScript
2,595
star
2

larapi

An API-friendly fork of Laravel. Authentication, error handling, resource filtering, sorting, pagination and much more included
PHP
404
star
3

bruno

A base API controller for Laravel that gives sorting, filtering, eager loading and pagination for your resources
PHP
164
star
4

heimdal

An Laravel Exception handler build specifically for APIs.
PHP
124
star
5

onion

A before/after middleware implementation
PHP
72
star
6

lumen-api-oauth

The code for a blog post I wrote about creating web apps using a Lumen API that is authenticated by OAuth2
PHP
61
star
7

oauth2-server-lumen

A lumen bridge for lucadegasperi/oauth2-server-laravel
PHP
56
star
8

jquery-oauth

A $.ajax wrapper for OAuth 2 access and refresh token management for use in a SPA
JavaScript
52
star
9

laravel-api-consumer

PHP
39
star
10

architect

Dynamically create API resource structures for related resources
PHP
39
star
11

redux-refresh-token

An extension to your Redux API middleware that will refresh access tokens when hitting a 401 response. Works with middlewares that use FSA-style actions.
JavaScript
37
star
12

distributed-laravel

PHP
30
star
13

genie

A base repository class for Eloquent to abstract away persistence layer from your business code
PHP
27
star
14

react-native-redux-form-example

Code for http://esbenp.github.io/2017/01/06/react-native-redux-form-immutable-styled-components/
JavaScript
22
star
15

wp-darkshell

A Next-Gen Wordpress Hacker Backend
PHP
15
star
16

fineuploader-server

PHP
7
star
17

pdf-bot-laravel

🤖 Laravel integration for pdf-bot. A Node microservice for generating PDFs using headless Chrome
PHP
5
star
18

larapi-series-part-2

PHP
4
star
19

cloudinary-url-resolver

Convert Cloudinary transformations and public ids to Cloudinary resource urls
JavaScript
4
star
20

laravel-batch-request

Batch consume own api
PHP
3
star
21

esbenp.github.io

Blog site
JavaScript
3
star
22

larapi-part-3

PHP
3
star
23

redux-refresh-token-example

Example app for redux-refresh-token
JavaScript
3
star
24

fineuploader-server-thumbnail-creator

PHP
3
star
25

fineuploader-server-cloudinary

PHP
2
star
26

knockout-null-observable

JavaScript
1
star
27

sentinel-lumen

PHP
1
star
28

react-native-swift-test

Objective-C
1
star
29

fineuploader-client-knockout

JavaScript
1
star
30

knockout-bootstrap-modal

JavaScript
1
star
31

laravel-package-boilerplate

PHP
1
star
32

knockout-subscriptions-manager

JavaScript
1
star
33

knockout-bulk-table

JavaScript
1
star
34

fineuploader-client

JavaScript
1
star
35

react-init

Boilerplate: Flow, Immutable, Redux, Redux Immutable, React Router, Styled Components, Webpack 3. Based on an ejected create-react-app.
JavaScript
1
star