Form.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import Module from '../lib/Module';
  3. import {StyleSheet ,TextInput, View, Button } from 'react-native';
  4. import Types from '../lib/Types';
  5. export default class FormComp extends Module {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. }
  10. this.submit = this.submit.bind(this)
  11. }
  12. submit(e){
  13. e.preventDefault()
  14. return this.state
  15. }
  16. display() {
  17. let {
  18. inputsNum,
  19. ButtonText,
  20. ButtonColor,
  21. container
  22. } = this.props
  23. if(!inputsNum) inputsNum = 2;
  24. let Inputs = [];
  25. for(let i = 0; i<inputsNum; i++){
  26. let key = i+1;
  27. let state = {};
  28. let input = <TextInput key={i}
  29. style={{height: 20, borderColor: 'gray', borderWidth: 1 , marginBottom:5}}
  30. onChangeText={(text) => {
  31. state[key] = text;
  32. this.setState(state)}}
  33. value={this.state.key}
  34. placeholder={'placeholder'}
  35. />
  36. Inputs.push(input);
  37. }
  38. let fn = this.props.submit || this.submit
  39. return (
  40. <View style={{backgroundColor:"#f7e6ff",width:250,height:100,padding:10}}>
  41. {Inputs}
  42. <Button
  43. onPress = {(e) => fn(e)}
  44. title={this.props.title || "Submit"}
  45. color={this.props.ButtonColor || "#008CBA"}
  46. accessibilityLabel="Learn more about this purple button"
  47. />
  48. </View>)
  49. }
  50. }
  51. FormComp.Inputs = {
  52. inputsNum: new Types.Integer().require().default(2),
  53. ButtonText:new Types.Text().require().default('Submit'),
  54. ButtonColor: new Types.Text().require().color().default('#008CBA')
  55. }