Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import * as React from "react"
  2. import { View, TextInput, TouchableOpacity } from "react-native"
  3.  
  4. import * as validate from "../../utils/validate"
  5.  
  6. export interface Props extends NavigationScreenProps<{}> {}
  7.  
  8. export interface State {
  9. form: {
  10. textInput: string;
  11. secondTextInput: string;
  12. };
  13. }
  14.  
  15. export class FirstExampleScreen extends React.Component<Props, State> {
  16. constructor(props: Props) {
  17. super(props);
  18.  
  19. this.state = {
  20. form: {
  21. textInput: '',
  22. secondTextInput: '',
  23. },
  24. }
  25. }
  26.  
  27. _validateForm = () => {
  28. const constraints = {
  29. textInput: {
  30. presence: true,
  31. length: {
  32. minimum: 5,
  33. },
  34. equality: 'premier',
  35. },
  36. secondTextInput: {
  37. presence: true,
  38. inclusion: ['test', 'tesT', 'TEST'],
  39. },
  40. }
  41.  
  42. const valid = validate.validate(constraints, this.state.form);
  43. console.log(`${JSON.stringify(valid)}`);
  44. }
  45.  
  46. render() {
  47. return (
  48. <View style={FULL}>
  49. <Screen
  50. style={CONTAINER}
  51. preset="scroll"
  52. backgroundColor={color.transparent}>
  53. <Text style={{ color: '#373737' }}>
  54. Premier input
  55. </Text>
  56. <TextInput
  57. style={{width: '80%', height: 60, borderColor: '#373737', borderWidth: 2}}
  58. onChangeText={(textInput) => this.setState({ form: { ...this.state.form, textInput } })}
  59. value={this.state.form.textInput} />
  60.  
  61. <Text style={{ color: '#373737' }}>
  62. Second input
  63. </Text>
  64. <TextInput
  65. style={{width: '80%', height: 60, borderColor: '#373737', borderWidth: 2}}
  66. onChangeText={(secondTextInput) => this.setState({ form: { ...this.state.form, secondTextInput } })}
  67. value={this.state.form.secondTextInput} />
  68.  
  69. <TouchableOpacity
  70. style={{ width: '50%', height: 35, backgroundColor: 'purple' }}
  71. onPress={this._validateForm}>
  72. <Text>Valider</Text>
  73. </TouchableOpacity>
  74. </Screen>
  75. </View>
  76. )
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement