Giter VIP home page Giter VIP logo

react-native-form-generator's Introduction

React Native Form Generator

Generate forms with native look and feel in a breeze

NPM

rnformgendatetimefields

react-native-form-generator

Components

  • Picker
  • DatePicker
  • TimePicker
  • Input
  • Link
  • Separator
  • Switch

Features

  • Android and IOS support, Yeah Baby!
  • Pleasant Defaults, totally overridable
  • Doesn't have dependencies
  • Use your own icon pack
  • Easy to use and clean, react style syntax
  • Automatic events handling
  • Supports custom fields and styles without adding any weird syntax (just create a react component)
  • Applies by default the current OS style
  • Inspired by tcomb, the good parts
  • Performances: just the field changed gets a setState
  • You don't need to create a 'Model' or a 'Struct' that contains your data, just create a form component (the React's way)
  • Validate InputFields based on keyboardType (can be overridden using validationFunction)
  • Multiple validators
  • Reset/Set Fields programmatically (setValue, setDate, setTime, focus)
  • Custom Wrapper for Picker & DatePicker Components (iOS Only)

My blogpost about React Native Form Generator

Installation

    npm install --save react-native-form-generator

I'm actively working on this project

  • Pull requests are very very welcome. They make my day ;).
  • Master should be considered 'unstable' even if I do my best to keep it nice and safe.
  • Every release has its own branch.
  • Slider hasn't been created.
  • I have to document the code properly and do some housekeeping, i apologize in advance.

Example

Please check the folder examples for an always up to date use case.

the example below generates the form you see in the animation

/*
This is a view i use in a test app,
very useful to list all the use cases
*/

import React from 'react';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,ScrollView,
} from 'react-native';


import { Form,
  Separator,InputField, LinkField,
  SwitchField, PickerField,DatePickerField,TimePickerField
} from 'react-native-form-generator';

export class FormView extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      formData:{}
    }
  }
  handleFormChange(formData){
    /*
    formData will contain all the values of the form,
    in this example.

    formData = {
    first_name:"",
    last_name:"",
    gender: '',
    birthday: Date,
    has_accepted_conditions: bool
    }
    */

    this.setState({formData:formData})
    this.props.onFormChange && this.props.onFormChange(formData);
  }
  handleFormFocus(e, component){
    //console.log(e, component);
  }
  openTermsAndConditionsURL(){

  }
  render(){
    return (<ScrollView keyboardShouldPersistTaps={true} style={{paddingLeft:10,paddingRight:10, height:200}}>
      <Form
        ref='registrationForm'
        onFocus={this.handleFormFocus.bind(this)}
        onChange={this.handleFormChange.bind(this)}
        label="Personal Information">
        <Separator />
        <InputField
          ref='first_name'
          label='First Name'
          placeholder='First Name'
          helpText={((self)=>{

            if(Object.keys(self.refs).length !== 0){
              if(!self.refs.registrationForm.refs.first_name.valid){
                return self.refs.registrationForm.refs.first_name.validationErrors.join("\n");
              }

            }
            // if(!!(self.refs && self.refs.first_name.valid)){
            // }
          })(this)}
          validationFunction={[(value)=>{
            /*
            you can have multiple validators in a single function or an array of functions
             */

            if(value == '') return "Required";
            //Initial state is null/undefined
            if(!value) return true;
            // Check if First Name Contains Numbers
            var matches = value.match(/\d+/g);
            if (matches != null) {
                return "First Name can't contain numbers";
            }

            return true;
          }, (value)=>{
            ///Initial state is null/undefined
            if(!value) return true;
            if(value.indexOf('4')!=-1){
              return "I can't stand number 4";
            }
            return true;
          }]}
          />
        <InputField ref='last_name' placeholder='Last Name'/>
        <InputField
          multiline={true}
          ref='other_input'
          placeholder='Other Input'
          helpText='this is an helpful text it can be also very very long and it will wrap' />
        <Separator />
        <LinkField label="test test test" onPress={()=>{}}/>
        <SwitchField label='I accept Terms & Conditions'
          ref="has_accepted_conditions"
          helpText='Please read carefully the terms & conditions'/>
        <PickerField ref='gender'
          label='Gender'
          options={{
            "": '',
            male: 'Male',
            female: 'Female'
          }}/>
          <DatePickerField ref='birthday'
          minimumDate={new Date('1/1/1900')}
          maximumDate={new Date()}
          placeholder='Birthday'/>
        <TimePickerField ref='alarm_time'
      placeholder='Set Alarm'/>
        <DatePickerField ref='meeting'
          minimumDate={new Date('1/1/1900')}
          maximumDate={new Date()} mode="datetime" placeholder='Meeting'/>
        </Form>
        <Text>{JSON.stringify(this.state.formData)}</Text>

      </ScrollView>);
    }
  }

Form

Form automatically attaches on change events so you just have to attach an handle to the onFocus attibute of Form to monitor all the changes.

It's just a wrapper that allows you to attach onFocus (used to track focus events and keyboard events) and onChange (used to track changes in every field)

Fields

Common Rules

  • Every field that has to propagate its value in the form MUST have a ref attribute. (Separator and LinkField don't have a ref). Check the example to understand the use of the ref attribute.
  • All the components provided use Field as wrapper in order to have the following props.
Prop (parameters) Description
helpText String shown as text under the component
helpTextComponent Custom component that replaces the one provided
onPress onPress method

Separator

  <Separator
    label="Example" // optional: if present it will show the text
    />

InputField

Input fields can be used to receive text, you can add icons (a react component) to the left and the right side of the field.

InputField can validate values based on keyboardType property, validation is not "aggressive", just changes a value inside the class, you can access the value using the ref (ex. this.ref.example_input_field.valid).
InputField automatically provides the attibutes valid and validationErrors to guarantee full control to the developer.

you can customize your validation function by adding a validationFunction prop to the component. validationFunction supports also an array of validators.

Creating a validator

Validators are simple functions have one paramenter (value) and that return true or a string containing an error.

let workingValidator = (value)=>{
  if(value == '') return "Required";
  //Initial state is null/undefined
  if(!value) return true;
  var matches = value.match(/\d+/g);
  if (matches != null) {
    return "First Name can't contain numbers";
  }

  return true;
}

react-native-form-generator doesn't depend on any icon library, that gives you freedom of adding any icon or react component you want.

look at the example here.

react-native-form-generator-inputfield

  <InputField
    label='Example' // if label is present the field is rendered with the value on the left (see First Name example in the gif), otherwise its rendered with textinput at full width (second name in the gif).
    ref='example_input_field' // used in onChange event to collect the value
    value='default_value' // used as initial value
    keyboardType = '' // undefined, 'email-address',
    validationFunction = {(value)=>{return true;}}
    iconRight={
      <Icon name='checkmark-circled'
        size={30}
        style={[
          {marginTop:7, color:"#61d062" },
          ((self)=>{
            //i can change the style of the component related to the attibute of example_input_field
            if(!!(self.refs && self.refs.example_input_field)){
              if(!self.refs.example_input_field.valid) return {color:'#d52222'}
            }
            }
          )(this)]}
        />
    }  //React Component
    />

All the props are passed down to the underlying TextInput Component

Prop (parameters) Description
label Text to show in the field, if exists will move the textinput on the right, providing also the right alignment
iconLeft React component, shown on the left of the field, the component needs to have a prop size to allow the inputText to resize properly
iconRight React component, shown on the right of the field, the component needs to have a prop size to allow the inputText to resize properly
validationFunction Function or array of functions, used to pass custom validators to the component
keyboardType possible values: undefined, email-address
ref methods Description
setValue Sets the value programmatically
focus Focus the textinput component

SwitchField

Prop (parameters) Description
onValueChange(value) triggered at every value change, returns the new value of the field
value Initial value of the component (Boolean)

PickerField

Prop (parameters) Description
onValueChange(value) triggered at every value change, returns the new value of the field
value Initial value of the component
options=[{label:"test",value="Test"},...] All the possible options, array of objects
iconRight React component, shown on the left of the text field (i suggest Ionicons 'ios-arrow-right' for a nice iOS effect)
pickerWrapper Optional, Custom wrapper of the picker, check the example

DatePickerField

Every prop is passed down to the underlying DatePickerIOS/DatePickerAndroid component.

Prop (parameters) Description
onValueChange(date) triggered at every value change, returns the new value of the field
date Initial date of the component, defaults to (new Date())
iconRight React component, shown on the left of the text field (i suggest Ionicons 'ios-arrow-right' for a nice iOS effect)
dateTimeFormat Optional, Custom date formatter
pickerWrapper Optional, Custom wrapper of the picker, check the example
prettyPrint Boolean, if true the component returns a string formatted using dateTimeFormat, if false a Date object is returned
placeholderComponent Substitutes the component used to render the placeholder
placeholderStyle Used to style the placeholder
valueStyle Used to style the field's value

TimePickerField

Every prop is passed down to the underlying DatePickerIOS/DatePickerAndroid component. Mode is set to 'time'

Prop (parameters) Description
onValueChange(date) triggered at every value change, returns the new value of the field
date Initial date of the component, defaults to (new Date())
iconRight React component, shown on the left of the text field (i suggest Ionicons 'ios-arrow-right' for a nice iOS effect)
dateTimeFormat Optional, Custom date formatter
pickerWrapper Optional, Custom wrapper of the picker, check the example
prettyPrint Boolean, if true the component returns a string formatted using dateTimeFormat, if false a Date object is returned
placeholderComponent Substitutes the component used to render the placeholder
placeholderStyle Used to style the placeholder
valueStyle Used to style the field's value

LinkField

Every prop is passed down to the underlying DatePickerIOS component.

Prop (parameters) Description
label Text to show in the field
iconLeft React component, shown on the left of the text field
iconRight React component, shown on the left of the text field (i suggest Ionicons 'ios-arrow-right' for a nice iOS effect)

KeyboardEvents

react-native-form-generator ships with an implementation ok KeyboardAwareScrollView that make handling keyboard events a breeze. check here https://medium.com/@michaelcereda/react-native-forms-the-right-way-315802f989d6#.p9oj79vt3

react-native-form-generator-keyevents

Custom Fields

With react-native-form-generator is extremely easy to create your own custom fields. You just need to know that:

  1. Every field is a react component
  2. Evey field will receive 3 props from the Form object:
    • fieldRef: contains the reference of the field (workaround on a react-native bug).
    • onChange: must be called every time i want to update the values inside the form component. (required)
    • onValueChange: can be used whenever you prefer to pass the values to another component.

Example

'use strict';
import {Field} from '../lib/Field';

export class SimpleInputField extends React.Component{
  constructor(props){
    super();
    }
  }

  handleChange(event){
    var value = event.nativeEvent.text;

    this.setState({value:value});

    // This updates values in form everytime i update
    if(this.props.onChange)      this.props.onChange(this.props.fieldRef, value);
    if(this.props.onValueChange) this.props.onValueChange(value);
  }

  render(){
    return(<Field>
        <TextInput
          {...this.props}
          ref='inputBox'

          onChange={this.handleChange.bind(this)}

          placeholder={this.props.placeholder}
          value={this.state.value}
          />
    </Field>
  )
}

}

Wrapping fields

You can decide to wrap every field in a component to mantain design uniformity and avoid repetitions (ex. Icons ?!).

Battle tested example

import {PickerField, LinkField} from 'react-native-form-generator';
import Icon from 'react-native-vector-icons/Ionicons';

let {
  StyleSheet
} = React;

export class WrappedLinkField extends React.Component{
  render(){

    return <LinkField
      label={this.props.label}
      onPress={this.props.onPress}
      iconRight={<Icon name='ios-arrow-right'
      size={30}
        />
    }
}

export class WrappedPickerField extends React.Component{
    render(){

      return <PickerField
        fieldRef = {this.props.fieldRef}
        value={this.props.value}
        placeholder={this.props.placeholder}
        options={this.props.options}
        onChange={this.props.onChange}
        onValueChange={this.props.onValueChange}
        iconRight={
          <Icon name='ios-arrow-right'
          size={30}

          style={[
            formStyles.alignRight,{color: '#C7C7CC'},
            this.props.iconStyle]}/>
      }
      />
  }
}

let formStyles = StyleSheet.create({
    alignRight:{
      marginTop: 7, position:'absolute', right: 10
    }
  });

react-native-form-generator's People

Contributors

adrienbrault avatar bjesus avatar brunocascio avatar enricogallus avatar gitter-badger avatar gwmccull avatar hans0low avatar jbrodriguez avatar kastopia avatar michaelarmfield avatar michaelcereda avatar rdebokx avatar shakarang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-form-generator's Issues

DatePickerField is too opinionated?

For my project, I'm styling DatePickerField exactly like an InputField.

Specifically, this means that there's placeholder text that gets replaced by the value, when value exists. This is a more literal interpretation of the word placeholder, as it seems like you're using placeholders like labels.

Presently I thought the only way to do this would be something like the following?:

        placeholder={()=>{ this.refs.datepicker....fieldvalue ? 'Birthday' : null }}

except the placeholder styling remains...

it would be nice if the current behavior was more opt-in, or at the very least could be styled depending on the state. I know this is kinda a pain without css-like classes, but maybe like the following?:

placeholderStyle={[ styles.regular, hasValue && styles.filled, isInvalid && styles.invalid ]}

or maybe even

placeholderComponent={<Placeholder />}

setValue issue

Good evening,

I found some issue in form generator, when I used setValue method system on InputField application is blocked for 10 second(unblocked when value was set)

SetTimePicker Crash

Hi i'm investigating, but at the moment the time picker crashes app. Using the example code, in android, running on samsung S7

Don't use bind in render()

Hey Michael

Got some warnings about "x events ahead of JS - try to make your JS faster" when using an InputField (with maxLength, not sure if that matters) and looked a little deeper at your code.

You shouldn't use this.func.bind(this) in render, as it creates a new function on every render. This might be the problem, as there are quite a few function binds in lib/*.js

You can bind in the constructor, or bind to the component instance with:

   boundFunction = () => {

  }

which makes this.boundFunction available in render without bind.

You might want to consider eslint with the react plugins, it's a lifesaver for me:
https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md

See also
http://reactkungfu.com/2015/07/why-and-how-to-bind-methods-in-your-react-component-classes/
https://medium.com/@esamatti/react-js-pure-render-performance-anti-pattern-fb88c101332f#.1l6dw4m4k

make displayed values a controlled prop

Hi!
thanks for the lib! One question: I'm using InputField and find it not ideal that the value of the entered text is stored in the state of the component and it is therefore possible for it to drift away from the value that is in my state object.
More specifically: I have my state object that contains the value that the text field should display. Say I render the textfield with value={this.state.value} (renders ok) then I change the value somewhere else which triggers a re-render. The InputField will ignore this new value. What I can do is use the setValue but I believe that goes against React.

So my question is - is it feasible to remove the value from state altogether (?), or alternatively implement componentWillReceiveProps? It doesn't seem difficult to get rid of it, looking at the code.
This might apply to other components too.

edit: so I tried both (getting rid of it & componentWillReceiveProps) and they seem to work both with no problem.

How to set value on a field programmatically

I'm trying to set value to a subsequent field based on onValueChange of another field. How would I go about doing that? I don't really see a way where the API expose that functionality? Thanks.

Suggest feature : touch form item to item.

Hello @MichaelCereda.
I use react-native-form-generator,

in your example, an inputfield to another inputfield situation.
touch

first inputfiield touch -> touch somewhere for hide keyboard -> second touch inputfield

how to remove unnecessary hide keyboard action?

datepickerfield invalidDate

Hello,
How to use datepickerfield? everytime I get invalidDate when I tried to set value.

example :

    value={new Date()} // invalidDate
    value={moment()} // invliadDate

please help me

Help Text

Unable to style help text would be nice to send style through props?

Android form looks broken (iOS works)

iOS:

ios

Android:

android

RN 0.30.0 / react-native-form-generator@^0.9.6

The form is pretty much a few simple links:

<Form>
  <Separator ... />
  <LinkField .../>
</Form>

What am I missing?

InputField: TextInput is cut off at the bottom if used with label

Tested with Android. Maybe this error is present on iOS too.

<InputField ref="hostname" label="Hostname" value={this.props.settings.hostname} placeholder="Hostname"/>
<InputField ref="path" label="Path" value={this.props.settings.path} placeholder="Path" />

screenshot_20160711-155813

refs not available

Hi,

<Form ref='form'>
   <TextInput  ref='hello' />
</Form>

it seems that

this.refs.hello

does not exist. Is Form stealing them? The only ref available when doing

console.log(Object.keys(this.refs))

is 'form'.

Wrap PickerField in Modal

Hey !

I've tried your example and I want to wrap a PickerField in the CustomModal.

It works fine with DatePickerField but not with the PickerField.

Here is my code

    <PickerField ref='height'
      label='Height (cm)'
      placeholder='100'
      prettyPrint={true}
      pickerWrapper={<CustomModal />}
      options={this.heightValues}
    />

    <DatePickerField ref='birthday'
      minimumDate={new Date('1/1/1900')}
      maximumDate={new Date()}
      placeholder='Birthday'
      mode='date'
      pickerWrapper={<CustomModal />}
    />

[Request] Programmatic focus

<InputField ref="thing" />

<TouchableHighlight onPress={this.refs.thing.focus}>Focus</TouchableHighlight>

Not currently possible, correct? Would be useful for quite a few purposes.

Unrecognized font family "Ionicons"

When I try to run your formsview.js example I get the red warning screen in the iPhone simulator saying "Unrecognized font family 'Ionicons'

Any idea what I can do to move beyond this point?
Thanks.

[Question] Modal DatePicker?

Great work! Thinking about ripping tcomb out and replacing it with yours.

What would be the best way to Modalize some components? For example, a date field that displays

MM/DD/YYYY

and when clicked, a full DatePicker comes up inside a Modal, not inline.

I assume this would necessitate a custom component; is there a clever way to extend without duplicating everything? I'm looking at your source now, but don't see a clear path to this goal.

edit: maybe a prop could replace this line in your new branch: https://github.com/MichaelCereda/react-native-form-generator/blob/0.9-beta/src/lib/DatePickerComponent.ios.js#L71 which would allow for a custom DatePicker view.

DatePickerField Warning

On ios, RN 27.2 the datepicker using the example code throws several warnings:

Warning: Failed propType: Invalid prop date of type Number supplied to RCTDatePicker, expected instance of Date. Check the render method of DatePickerIOS.

Warning: Failed propType: Required prop onDateChange was not specified in RCTDatePicker. Check the render method of DatePickerIOS.

Warning: Failed propType: Invalid prop maximumDate of type Number supplied to RCTDatePicker, expected instance of Date. Check the render method of DatePickerIOS.

Warning: Failed propType: Invalid prop minimumDate of type Number supplied to RCTDatePicker, expected instance of Date. Check the render method of DatePickerIOS.

helpText not shown

Not sure why, but helpText is not shown for <LinkField>. It only works for <SwitchField>.

 <Form ref='logInForm' label="Information" onChange={this._handleFormChange.bind(this)}>
    <Separator label='Please read'/>
    <LinkField label='Terms and Conditions'
                               onPress={this._openTermsAndConditions.bind(this)}
                               helpText='By signing up, I agree to the terms and conditions.'/>
</Form>

Wrapped Icons break InputField layout?

import Icon from 'react-native-vector-icons/FontAwesome';
class Icon2 extends Component {
  render() {
    return (
      <Icon {...this.props} />
    );
  }
}
<InputField iconLeft={<Icon2 />} />

Seems to break layout in input fields โ€“ the actual input field / placeholder will disappear.

How to make a password field?

I was looking around the examples and the docs, but I couldn't find anywhere an option for the to be with asterisks, to be a password field. Is there a way to do that?

Tapping twice to get to other input field

Hi @MichaelCereda

I'm thinking of contributing to this repo. What I noticed, and what annoys me A LOT is that, when using the TextInput component, you have to tap twice on a TextInput to get to another TextInput. On first touch on another TextInput, the keyboard hides, I think in iOS it's called something like "resigning first responder", not sure though. And then on second touch, one can focus the next TextInput.

Do you have any Idea on what the issue could be here? This is a really strange behaviour, and when you try out true native apps you won't see this.

Thanks

dateTimeFormat

How are we to use the dateTimeFormat prop for TimePickerField and DatePickerField? For example, I only want the time to display as '5:30 PM', not '5:30:22 PM. Essentially, I don't want to seconds to show up, as they're kind of unnecessary for my case.

Any help would be greatly appreciated.

PickerField not responding to onFocus or onPress events

Using the following example:

<PickerField ref='state'
label='State'
onFocus={() => {console.log("test onFocus")}}
onPress={() => {console.log("onPress of state picker");}}
options={stateOptions}/>

These events do not seem to be firing.

Default value not stored in formData unless field was changed.

Using the code below, this.state.formData.gender remains"undefined", unless the picker was set to a different value (and back in case you actually want the default value). I think the desired behavior would be that this.state.formData.gender is set to "M" in this situation, even when the user does not change the picker value.

handleFormChange(formData){
  this.setState({formData:formData})
}

render(){
  return(<ScrollView keyboardShouldPersistTaps={true} style={{marginTop: h.scale(50), paddingLeft:10,paddingRight:10, height:200}}>
  <Form
    ref='paymentForm'
    onChange={this.handleFormChange.bind(this)}>

    <PickerField
      ref='gender'
      label='Gender'
      value='M'
      options={M: "Male", F: "Female"}/>
    </Form>
  </ScrollView>);
}

Difference between iOS and Android

In iOS everything work but on Android the "right Icon" is not on the same line.. Do you know why ?

Here's my code :
<InputField ref='login' placeholder={I18n.t('mail')} returnKeyType={"next"} keyboardType={"email-address"} validationFucntion={this.props.validateLogin} iconRight={ <Icon name='ios-arrow-forward' size={30} style={[ {alignSelf:'center',marginRight:10, color: "#61d062"}, ((self) => { if (!!(self.refs.loginForm && self.refs.loginForm.refs.login)) { if (!self.refs.loginForm.refs.login.valid) return {color: '#d52222'} } })(this)]} /> } onEndEditing={() => { this.props.validateLogin(); this.refs.loginForm.refs.pwd.focus() }} />

why split android and ios versions?

I saw that each field type has two different versions. One for ios and one for android (for example InputField.ios.js and InputField.android.js).
What is the reason for this? That seems to go completely against the philosophy of react-native (having a unified version of an app between different platforms) and is a potential source of inconsistencies (like 'right Icon' that appear on the same lime as the textfield on ios but on a different one on android due to different default stylesheets between the two classes...)
To me, it would make more sense to have android and ios share as much code as possible (same default stylesheets and templates...)

[Android] Date/Time PickerFields aren't similar enough cross-platform

Without building on iOS, I'm going by what I'm seeing in the README as how things look there. There is a drastic difference on the Android side. Focusing on the Date/Time fields, the DatePickerField will only being up a date picker but on iOS it looks date and time are nicely inline. So on Android and only Android I need to add an extra time picker? This doesn't seem ideal.

Can a pure js picker be used? Something like this. I think it would need to be modified but I think parity between platforms is worth it. The iOS version is pretty sleek though. It's a challenge to reproduce it but I'm game if someone can help me develop it out a bit.

How to disable fields?

I need my input forms to be read-only until I put them in edit mode.

So I need to manage editable and disabled props of the fields.

InputField is easy:

<InputField
      placeholder='Namn'
      ref='contactName'
      editable={this.props.isEditable}
/>

SwitchField is not easy. I'd like to do like this:

 <WrappedSwitchField
  value={this.props.project.isActive}
  disabled={!this.props.isEditable}
  label='Active'
/>

or even

 <WrappedSwitchField
  value={this.props.project.isActive}
  editable={this.props.isEditable}
  label='Active'
/>

But the switch field doesn't propagate the disabled prop to the internal switch. I could make a custom field, of course. But it would be nice if all form-generator fields were disableable (is that a word?). It would also be great if the editable prop where used everywhere (instead of disabled for switches)

How about one new line in SwitchComponent.js?

//src/lib/SwitchComponent.js
render(){
  return(<Field {...this.props}>
    <View style={this.props.containerStyle}
      onLayout={this.handleLayoutChange.bind(this)}>

      <Text style={this.props.labelStyle}>{this.props.label}</Text>
        <Switch
        onValueChange={this.handleValueChange.bind(this)}
        style={this.props.switchStyle}
        value={this.state.value} 

-->     disabled={ (typeof this.props.editable === 'undefined') ? false : !this.props.editable }/>        

    </View>

  </Field>
  )
}

SetValue() on PickerField

Hey !

How can I use setValue() on Picker row?

The code in "normal" fields works but not with Picker.

this.refs.registrationForm.refs.password.setValue(""); // OK 
this.refs.registrationForm.refs.height.setValue(store.user.user.height); // NOT OK

Android TextInput doesn't display its UI

Hi, it's mostly a heads-up, since you're working on a new version.

I had opened this issue (facebook/react-native#9862) on RN, but after isolating the issue, I found out it is a form-generator issue.

I commented InputComponent.js so that handleLayoutChange and handleLabelLayoutChange are no-ops.

I'm not sure about the implications, but it's working fine in my Android app so far.

  handleLayoutChange(e){
    // let {x, y, width, height} = {... e.nativeEvent.layout};
    //
    // this.setState(e.nativeEvent.layout);
    // //e.nativeEvent.layout: {x, y, width, height}}}.
  }

  handleLabelLayoutChange(e){
    // let {x, y, width, height} = {... e.nativeEvent.layout};
    //
    // this.setState({labelWidth:width});
    // //e.nativeEvent.layout: {x, y, width, height}}}.
  }

helpTextComponent option doesn't work

I have tried to override the help text component with mine but it doesn't work
After a few tests it comes from the file Field.js
I added brackets for the second part of the evaluation expression to fix it.

------- before --------
let fieldHelpText =
this.props.helpTextComponent
|| (this.props.helpText)
?
: null;

------- after ----------
let fieldHelpText =
this.props.helpTextComponent
|| ((this.props.helpText)
?
: null);

Maybe it comes from the evaluation order.
Could you reintegrate this fix please?

Thanks

PA

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.