React Native Redux表单无法在字段中显示默认值,并在更改下拉列表时更新字段值

时间:2019-12-10 14:00:24

标签: react-native redux-form

现在使用React Native和Redux表单,我在加载屏幕时显示redux Form Field的默认值时遇到问题,并且在另一个字段中发生更改时更新同一字段。

  <SearchableDropdown  style={styles.inputBox}
      onItemSelect={item => this.getServiceCategories(JSON.stringify(item.id))}
      containerStyle={{ padding: 5 }}
      textInputStyle={{
        padding: 12,
        borderWidth: 1,
        borderColor: '#ccc',
        borderRadius: 15,
        color: '#000',
        width:300
      }}
      itemStyle={{
        padding: 10,
        marginTop: 2,
        backgroundColor: '#ddd',
        borderColor: '#fff',
        borderWidth: 1,
        borderRadius: 15,
        color: '#000',
      }}
      itemTextStyle={{ color: '#000' }}
      itemsContainerStyle={{ maxHeight: 240 }}
      items={this.state.serviceData}
      defaultIndex={0}
      placeholder="Select Service"
      resetValue={false}
      underlineColorAndroid="transparent"
    />

    <Field style={styles.inputBox}
        name="categoryid"
        value={this.state.CategoryName}
        placeholder="Category"
        returnKeyLabel={this.state.CategoryID}
        component={this.renderTextInput} />

  renderTextInput = (field) => {
    const {meta: {touched, error}, label, secureTextEntry, maxLength,value,keyboardType, placeholder, input: {onChange, ...restInput}} = field;
    return (
        <View>
          <InputText
              onChangeText={onChange}
              maxLength={maxLength}
              placeholder={placeholder}
              keyboardType={keyboardType}
              value ={value}
              secureTextEntry={secureTextEntry}
              label={label}
              {...restInput} />
        {(touched && error) && <Text style={styles.errorText}>{error}</Text>}
        </View>
    );

}

第一个问题是加载时,我无法显示默认值<Field value="test" >可能是renderTextInput函数引起的。

第二,我想在更改下拉选项时更新<Field value="text 1">

任何帮助

0 个答案:

没有答案