question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formvalidation not working

See original GitHub issue

Version

Tell us which versions you are using:

  • tcomb-form-native master-branch
  • react-native v0.23.1

Expected behaviour

Error message that field is empty

Actual behaviour

RegisterDetails.js page opens without validating the form of Register.js. There are no error messages

Steps to reproduce

I splitted the Form and started creating a FormLoader.

this is my FormLoader.js

export default class FormLoader extends React.Component {
    propTypes : {
        formType: PropTypes.string,
        form: PropTypes.object,
        style: Form.propType.style,
        value: PropTypes.object,
        onChange: PropTypes.func
    };

    render() {


        let options = {
            auto: 'none',
            fields: {},
            state: '',

        };

        let usernameOpt = {
            placeholder: 'Username',
            hasError: false,
            error: 'Please enter a Username'
        };

        let passwordOpt = {
            placeholder: 'Passwort',
            password: true,
            hasError: false,
            error: 'Please enter Password'
        };

        var max3 = s => s.length <= 3;
        var username = t.refinement(t.String, s=> max3(s));

        username.getValidationErrorMessage = s => {
            if(!s){
                return 'We need a name to proceed!';
            }
            if(!max3(s)){
                return 'test test test';
            }
        };

        let formType = this.props.formType;
        switch (formType) {
            case(REGISTER):
                formLoader = t.struct({
                    username: username,
                    password: t.String,
                });
                options.fields['username'] = usernameOpt;
                options.fields['password'] = passwordOpt;
                break;
        }

        return (
            <Form ref="form"
                  type={formLoader}
                  options={options}
                  value={this.props.value}
                  onChange={this.props.onChange}
                  isValid={true}
            />
        );
    }
}

and this is my Register.js

...
import {Actions} from "react-native-router-flux";
import FormLoader from "../../lib/FormLoader";
...

export default class Register extends React.Component {
    constructor() {
        super();
        this.onChange = this.onChange.bind(this);
        this.state = {
            user: {}
        }
    }

    _continueRegistration() {
        Actions.registerDetails(value);
    }

    onChange(value) {
        this.state.user = value;
    }

    render() {
        return (
            <View style={styles.container}>
                <View style={styles.input}>
                    <FormLoader ref="form"
                                formType={REGISTER}
                                value={this.state.user}
                                onChange={this.onChange}
                    />
                    <Button onPress={this._continueRegistration.bind(this)}>Continue</Button>
                </View>
            </View>
        );
    }
}

I would be happy if anyone can help me here…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alvarombcommented, Apr 15, 2016

With a custom refinement

const PasswordMinLength = t.refinement(t.String, value => {
  return value.length > 6
})
// Validate repeat password
const ConfirmPasswordEquality = t.refinement(t.String, value => {
  return value === this.state.value.password
})

const Form = t.struct({
  password: PasswordMinLength,
  confirm_password: ConfirmPasswordEquality,
})

Remember to save your Form state into the value object.

1reaction
alvarombcommented, Apr 15, 2016

Inside FormLoader:

...
getValue () {
  return this.refs.form.getValue()
}
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

html form validation not working - Stack Overflow
I was working on a html form where I have to enter user information and on submit. It will navigate to the php...
Read more >
Can not submit form after validation - FormValidation
Can not submit form after validation. There are some mistakes causing the issue that the form can't be submitted although the validation is...
Read more >
Javascript form validation not working? - SitePoint
You need the validation function to execute the json submit code. That can be done by moving the json submit function to a...
Read more >
Form Validation not working - JavaScript - Codecademy Forums
I just wanted to create a client-side Form-Validation for my Registration Form. I set it up to start checking the input once I...
Read more >
6 Reasons - HTML5 Required Attribute Validation not Working
1. The Form Tag has “novalidate” Attribute · 2. Required Attribute Validation doesn't Work with Unclosed Input Tags · 3. The Button is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found