Giter Site home page Giter Site logo

Comments (1)

gcanti avatar gcanti commented on September 7, 2024

I can't reproduce your error.

My setup:

  • tcomb-form-native v0.2.2
  • react-native v0.5.0

This snippet works fine if can be helpful:

var Form = t.form.Form;

var Credentials = t.struct({
  username: t.Str,
  password: t.Str
});

var AwesomeProject = React.createClass({

  getInitialState() {
    return {
      value: {},
      options: {
        fields: {
          username: {},
          password: {
            password: true
          }
        }
      }
    };
  },

  onChange(value) {
    this.setState({value});
  },

  onPress() {
    var value = this.refs.form.getValue();
    if (value) {
      // disable al fields while submitting
      this.setState({
        options: t.update(this.state.options, {
          fields: {
            username: {
              editable: {'$set': false}
            },
            password: {
              editable: {'$set': false},
              hasError: {'$set': false},
              error: {'$set': null}
            }
          }
        })
      });
      // fake server call
      setTimeout(() => {
        this.setState({
          options: t.update(this.state.options, {
            fields: {
              username: {
                editable: {'$set': true}
              },
              password: {
                editable: {'$set': true},
                hasError: {'$set': true},
                error: {'$set': 'Server error!'}
              }
            }
          })
        });
      }, 2000);
    }
  },

  render() {
    return (
      <View style={styles.container}>
        <Form
          ref="form"
          type={Credentials}
          options={this.state.options}
          value={this.state.value}
          onChange={this.onChange}
        />
        <TouchableHighlight style={styles.button} onPress={this.onPress} underlayColor='#99d9f4'>
          <Text style={styles.buttonText}>Save</Text>
        </TouchableHighlight>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: 50,
    padding: 20,
    //backgroundColor: '#333333'
    backgroundColor: '#ffffff'
  },
  title: {
    fontSize: 30,
    alignSelf: 'center',
    marginBottom: 30
  },
  buttonText: {
    fontSize: 18,
    color: 'white',
    alignSelf: 'center'
  },
  button: {
    height: 36,
    backgroundColor: '#48BBEC',
    borderColor: '#48BBEC',
    borderWidth: 1,
    borderRadius: 8,
    marginBottom: 10,
    alignSelf: 'stretch',
    justifyContent: 'center'
  }
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

from tcomb-form-native.

Related Issues (20)

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.