Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Validation issue #10

Open
tbiinfotech opened this issue Feb 27, 2018 · 3 comments
Open

Form Validation issue #10

tbiinfotech opened this issue Feb 27, 2018 · 3 comments

Comments

@tbiinfotech
Copy link

Form validation not working: You attempted to set the key backgroundColor with the value "transparent" on an object that is meant to be immutable and has been frozen.

@ajiehatajie
Copy link

same issue

@Q8hma
Copy link

Q8hma commented Dec 22, 2018

Hello
you can fix it by replace this code on Picker Field file


import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { View, Text } from 'native-base';
import { Platform, Picker, TouchableOpacity } from 'react-native';
import Panel from '../../components/panel';
import styles from './../../styles';

const Item = Picker.Item;
export default class PickerField extends Component {
  static propTypes = {
    attributes: PropTypes.object,
    theme: PropTypes.object,
    updateValue: PropTypes.func,
    ErrorComponent: PropTypes.func,
  }
  handleChange(value) {
    const attributes = this.props.attributes;
    this.props.updateValue(attributes.name, attributes.options[value]);
  }
  render() {
    const { theme, attributes, ErrorComponent } = this.props;
    const isValueValid = attributes.options.indexOf(attributes.value) > -1;
    const pickerValue = attributes.options.indexOf(attributes.value).toString();
    if (Platform.OS !== 'ios') {
      return (
        <View
          style={{...styles.pickerMainAndroid, ...{
            backgroundColor: theme.pickerBgColor,
            borderBottomColor: theme.inputBorderColor,
            borderBottomWidth: theme.borderWidth,
          }}}
        >
          <View style={{ flex: 7 }}>
            <Text style={{ color: theme.inputColorPlaceholder }}>{attributes.label}</Text>
          </View>
          <View style={{ flex: 3 }}>
            <Picker
              style={{ padding: 2 }}
              textStyle={{ color: theme.pickerColorSelected }}
              iosHeader="Select one"
              mode={attributes.mode}
              selectedValue={pickerValue}
              onValueChange={value => this.handleChange(value)}
            >{
                attributes.options.map((item, index) => (
                  <Item key={index} label={item} value={`${index}`} />
                ))
              }
            </Picker>
          </View>
          <ErrorComponent {...{ attributes, theme }} />
        </View>
      );
    }
    return (
      <View
        style={{...styles.pickerMainAndroid, ...{
            backgroundColor: theme.pickerBgColor,
            borderBottomColor: theme.inputBorderColor,
            borderBottomWidth: theme.borderWidth,
          }}}
      >
        <TouchableOpacity
          onPress={() => this.panel.toggle()}
          style={{
            flex: 1,
            flexDirection: 'row',
            justifyContent: 'space-between',
            alignItems: 'center',
            paddingVertical: 10,
          }}
        >
          <Text style={{ color: theme.inputColorPlaceholder }}>
            {attributes.label}
          </Text>
          <Text style={{ color: theme.inputColorPlaceholder }}>
            {isValueValid ? attributes.value : 'None'}
          </Text>
        </TouchableOpacity>
        <ErrorComponent {...{ attributes, theme }} />
        <View style={{ flex: 1 }}>
          <Panel
            ref={(c) => { this.panel = c; }}
          >
            <Picker
              style={{ padding: 2 }}
              textStyle={{ color: theme.pickerColorSelected }}
              mode={attributes.mode}
              selectedValue={pickerValue}
              onValueChange={value => this.handleChange(value)}
            >{
                attributes.options.map((item, index) => (
                  <Item key={index} label={item} value={`${index}`} />
                  ))
              }
            </Picker>
          </Panel>
        </View>
      </View>

    );
  }
}

@angelalalachang
Copy link

I got the same issue, and exactly as @Q8hma suggested above, making those changes in /src/fields/picker/index.js would fix this bug.

The changes you need to make is perhaps summarized more clearly in this issue thread (#22) by @mbs8: Picker iOS Error http://github.com/bietkul/react-native-form-builder/issues/22

Duplicate of #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants