<commit_before>import React, {Component} from 'react';
import {connect} from 'react-redux';
import { createFieldClass, controls, actions } from 'react-redux-form';
import {validate, server} from '../actions';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import diff from 'seamless-immutable-diff';
import Differ from '../core/differ';
import Immutable from 'seamless-immutable';
import {Input} from 'react-bootstrap';

const ReactBootstrapField = createFieldClass({
  'Input': controls.text
});

class EfficientlyField extends Component {
  shouldComponentUpdate(nextProps, nextState) {
    // return Object.keys(new Differ().diff(this.props, nextProps)).length > 0;
    return this.props != nextProps;
  }

  render() {
    let {field, model, cols = "2,4", type = "text", validators = [], validateOn, dispatch, valid, error} = this.props;

    let helpText = field.touched && error ? helpText + " " + error : helpText;

    this.changeAction = this.changeAction || (validateOn && validateOn.toLowerCase() === "change"
      ? (extendedModel, value) => (dispatch) => {
          dispatch(actions.change("clientSideFormData." + model + ".value", value));
          dispatch(server(validate(model)));
        }
      : (extendedModel, value) => (dispatch) => {
          dispatch(actions.change("clientSideFormData." + model + ".value", value));
        });

    this.onBlurAction = this.onBlurAction || (validateOn && validateOn.toLowerCase() === "blur"
      ? () => dispatch(server(validate(model)))
      : undefined);

    // TODO use validateOn, don't always send server(validate(...)) on change!
    return (
      <ReactBootstrapField
        model={"clientSideFormMetaData." + model}
        changeAction={this.changeAction}
        >
        <Input
          standalone
          hasFeedback
          bsStyle={field.touched && (!field.valid || valid === false) ? "error" : field.touched ? "success" : null}
          help={helpText ? helpText : null}
          labelClassName={"col-xs-" + cols.split(',')[0]}
          wrapperClassName={"col-xs-" + cols.split(',')[1]}
          {...this.props}
          type={type}
          onBlur={this.onBlurAction}
          />
      </ReactBootstrapField>
    )
  }
}

export default EfficientlyField;<commit_msg>show field validation when either touched or focused<commit_after>import React, {Component} from 'react';
import {connect} from 'react-redux';
import { createFieldClass, controls, actions } from 'react-redux-form';
import {validate, server} from '../actions';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import diff from 'seamless-immutable-diff';
import Differ from '../core/differ';
import Immutable from 'seamless-immutable';
import {Input} from 'react-bootstrap';

const ReactBootstrapField = createFieldClass({
  'Input': controls.text
});

class EfficientlyField extends Component {
  shouldComponentUpdate(nextProps, nextState) {
    // return Object.keys(new Differ().diff(this.props, nextProps)).length > 0;
    return this.props != nextProps;
  }

  render() {
    let {field, model, cols = "2,4", type = "text", validators = [], validateOn, dispatch, valid, error} = this.props;

    let helpText = field.touched && error ? helpText + " " + error : helpText;

    this.changeAction = this.changeAction || (validateOn && validateOn.toLowerCase() === "change"
      ? (extendedModel, value) => (dispatch) => {
          dispatch(actions.change("clientSideFormData." + model + ".value", value));
          dispatch(server(validate(model)));
        }
      : (extendedModel, value) => (dispatch) => {
          dispatch(actions.change("clientSideFormData." + model + ".value", value));
        });

    this.onBlurAction = this.onBlurAction || (validateOn && validateOn.toLowerCase() === "blur"
      ? () => dispatch(server(validate(model)))
      : undefined);

    // TODO use validateOn, don't always send server(validate(...)) on change!
    return (
      <ReactBootstrapField
        model={"clientSideFormMetaData." + model}
        changeAction={this.changeAction}
        >
        <Input
          standalone
          hasFeedback
          bsStyle={(field.touched || field.focus) && (!field.valid || valid === false) ? "error" : field.touched ? "success" : null}
          help={helpText ? helpText : null}
          labelClassName={"col-xs-" + cols.split(',')[0]}
          wrapperClassName={"col-xs-" + cols.split(',')[1]}
          {...this.props}
          type={type}
          onBlur={this.onBlurAction}
          />
      </ReactBootstrapField>
    )
  }
}

export default EfficientlyField;
{'fraction_non_alphanumeric': 0.1540962288686606, 'fraction_numerical': 0.002167316861725184, 'mean_word_length': 3.1916439600363304, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '3592675', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1342, 'n_words': 299}