Formvalidation not working
See original GitHub issueVersion
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:
- Created 7 years ago
- Comments:13 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With a custom
refinement
Remember to save your
Form
state into thevalue
object.Inside
FormLoader
: