<commit_before>import React from 'react';


export default function(WrappedComponent) {
  const Field = React.createClass({
    getInitialState() {
      return {
        value: this.props.initialValue,
        message: this.props.message,
        valid: true,
        timestamp: 0
      };
    },

    componentWillMount() {
      if (this.props.value) {
        this.setState({checked: this.props.value === this.state.value});
      }
    },

    componentDidUpdate(prevProps) {
      if (prevProps.value !== this.props.value) {
        this.setState({value: this.props.value});
      }
      if (prevProps.message !== this.props.message) {
        this.setState({message: this.props.message});
      }
    },

    validate() {
      if (this.props.validators) {
        for (let validator of this.props.validators) {
          let result = validator(this.state.value);
          if (result !== true) {
            this.setState({valid: false, message: result});
            return false;
          }
        }
      }
      this.setState({valid: true, message: ''});
      return true;
    },

    handleChange(event) {
      this.setState({timestamp: Date.now()});

      return new Promise((resolve) => {
        switch (event.target.type) {
          case 'checkbox':
            this.setState({value: event.target.checked}, resolve);
            break;
          case 'select-multiple':
            this.setState({
              value: Array.from(event.target.selectedOptions).map((option) => {
                return option.value;
              })}, resolve);
            break;
          default:
            this.setState({value: event.target.value}, resolve);
        }
      });
    },

    elementProps() {
      console.log(this.props.name, this.state.checked);<commit_msg>Handle onChange event for radio fields<commit_after>import React from 'react';


export default function(WrappedComponent) {
  const Field = React.createClass({
    getInitialState() {
      return {
        value: this.props.initialValue,
        message: this.props.message,
        valid: true,
        timestamp: 0
      };
    },

    componentWillMount() {
      if (this.props.value) {
        this.setState({checked: this.props.value === this.state.value});
      }
    },

    componentDidUpdate(prevProps) {
      if (prevProps.value !== this.props.value) {
        this.setState({value: this.props.value});
      }
      if (prevProps.message !== this.props.message) {
        this.setState({message: this.props.message});
      }
    },

    validate() {
      if (this.props.validators) {
        for (let validator of this.props.validators) {
          let result = validator(this.state.value);
          if (result !== true) {
            this.setState({valid: false, message: result});
            return false;
          }
        }
      }
      this.setState({valid: true, message: ''});
      return true;
    },

    handleChange(event) {
      this.setState({timestamp: Date.now()});

      return new Promise((resolve) => {
        switch (event.target.type) {
          case 'checkbox':
            this.setState({value: event.target.checked}, resolve);
            break;
          case 'radio':
            this.setState({value: event.target.value}, () => {
              this.setState({checked: this.props.value === this.state.value}, resolve);
            });
            break;
          case 'select-multiple':
            this.setState({
              value: Array.from(event.target.selectedOptions).map((option) => {
                return option.value;
              })}, resolve);
            break;
          default:
            this.setState({value: event.target.value}, resolve);
        }
      });
    },

    elementProps() {
      console.log(this.props.name, this.state.checked);
{'fraction_non_alphanumeric': 0.13940666841690733, 'fraction_numerical': 0.0005250721974271463, 'mean_word_length': 1.9039634146341464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1620134', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1050, 'n_words': 197}