How to add a value to an inputText in tcomb-form-native?

爱⌒轻易说出口 提交于 2019-12-13 20:08:58

问题


I'am new in react native , and i'am using tcomb-form library to create forms for my app. I want to add a default values to some of my fields, means when they first appear they must have values by default. This is what i tried so far but the field still appears empty :

this.Position = t.struct({
      PosName: FormFields.String,
    });
fields:{
PosName: {
          placeholder: "Name der Position",
          error: "Dieses Feld ist erforderlich",
          label: "Name der Position",
          value: "some text here ",
          template: Template
        },
//... other fields here
}

回答1:


You can create an object with your fields and your default values and then pass it to your form element like this:

// your object definition
    let value = {
         PostName: 'some text here',
         {... other fields}
    }

And then on your render:

<Form type={this.Position} value={value}

Here's the docs: tcomb-form-native default values



来源:https://stackoverflow.com/questions/50004479/how-to-add-a-value-to-an-inputtext-in-tcomb-form-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!