<commit_before>import React from 'react';
import {
  View,
  ScrollView,
  Text
} from 'react-native';
import { Field } from 'redux-form';

import CheckBtn from 'components/common/form-inputs/check-btn';
import TextInput from '../text-detail';
import styles from '../styles';


function SelectInput(props) {
  function handlePress(value) {
    const newVal = [...props.input.value];
    const index = newVal.indexOf(value);
    if (index >= 0) {
      newVal.splice(index, 1);
    } else {
      newVal.push(value);
    }
    props.input.onChange(newVal);
  }
  const { childQuestions } = props.question;
  return (
    <View style={styles.container}>
      <Text style={styles.label}>{props.question.label}</Text>
      <ScrollView
        style={styles.containerContent}
        showsVerticalScrollIndicator={false}
        showsHorizontalScrollIndicator={false}
      >
        {props.question.values.map((value, index) => {
          const checked = props.input.value.indexOf(value) >= 0;
          let conditionalField = null;
          if (childQuestions && childQuestions.length && childQuestions[0].conditionalValue === value) {
            conditionalField = (
              <Field
                visible={checked}
                name={childQuestions[0].name}
                component={TextInput}
                question={childQuestions[0]}
              />
            );
          }
          return [
            <CheckBtn
              key={index}
              value={value}
              checked={checked}
              onPress={() => handlePress(value)}
            />,
            conditionalField
          ];
        })}
      </ScrollView>
    </View>
  );
}

SelectInput.propTypes = {
  question: React.PropTypes.shape({
    label: React.PropTypes.string,
    defaultValue: React.PropTypes.string,
    values: React.PropTypes.array
  }).isRequired,
  input: React.PropTypes.shape({
    onBlur: React.PropTypes.func.isRequired,
    onChange: React.PropTypes.func.isRequired,
    onFocus: React.PropTypes.func.isRequired,
    value: React.PropTypes.any.isRequired
  }).isRequired,
  meta: React.PropTypes.shape({
    active: React.PropTypes.bool.isRequired,
    error: React.PropTypes.string,
    invalid: React.PropTypes.bool.isRequired,
    pristine: React.PropTypes.bool.isRequired,
    visited: React.PropTypes.bool.isRequired
  }).isRequired<commit_msg>Feat: Forms - Multiple select conditionals<commit_after>import React from 'react';
import {
  View,
  ScrollView,
  Text
} from 'react-native';
import { Field } from 'redux-form';

import CheckBtn from 'components/common/form-inputs/check-btn';
import TextInput from '../text-detail';
import styles from '../styles';


function SelectInput(props) {
  function handlePress(value) {
    const newVal = [...props.input.value];
    const index = newVal.indexOf(value);
    if (index >= 0) {
      newVal.splice(index, 1);
    } else {
      newVal.push(value);
    }
    props.input.onChange(newVal);
  }
  const { childQuestions } = props.question;
  return (
    <View style={styles.container}>
      <Text style={styles.label}>{props.question.label}</Text>
      <ScrollView
        style={styles.containerContent}
        showsVerticalScrollIndicator={false}
        showsHorizontalScrollIndicator={false}
      >
        {props.question.values.map((value, index) => {
          const checked = props.input.value.indexOf(value) >= 0;
          let conditionalField = null;
          if (childQuestions && childQuestions.length > 0) {
            childQuestions.forEach(childConditional => {
              if (value === childConditional.conditionalValue) {
                conditionalField = (
                  <Field
                    visible={checked}
                    name={childConditional.name}
                    component={TextInput}
                    question={childConditional}
                  />
                );
              }
            });
          }
          return [
            <CheckBtn
              key={index}
              value={value}
              checked={checked}
              onPress={() => handlePress(value)}
            />,
            conditionalField
          ];
        })}
      </ScrollView>
    </View>
  );
}

SelectInput.propTypes = {
  question: React.PropTypes.shape({
    label: React.PropTypes.string,
    defaultValue: React.PropTypes.string,
    values: React.PropTypes.array
  }).isRequired,
  input: React.PropTypes.shape({
    onBlur: React.PropTypes.func.isRequired,
    onChange: React.PropTypes.func.isRequired,
    onFocus: React.PropTypes.func.isRequired,
    value: React.PropTypes.any.isRequired
  }).isRequired
{'fraction_non_alphanumeric': 0.12371355060034306, 'fraction_numerical': 0.002144082332761578, 'mean_word_length': 2.2128099173553717, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1881527', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1289, 'n_words': 233}