<commit_before>import _ from 'lodash';
import $ from 'jquery';
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import META from 'src/utils/Meta';

export default class Form extends Component {
  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    settings: PropTypes.object,
  };

  componentDidMount() {
    this.element = $(this.refs.element);
    this.element.form(this.props.settings);
  }

  componentWillUnmount() {
    this.element.off();
  }

  plugin() {
    return this.element.form(...arguments);
  }

  serializeJson = () => {
    const form = this.refs.form;
    const json = {};

    _.each(['input', 'textarea', 'select'], (tag) => {
      _.each(form.getElementsByTagName(tag), (node, index, arr) => {
        const name = node.getAttribute('name');

        switch (node.getAttribute('type')) {
          case 'checkbox':
            json[name] = {checked: node.checked};
            break;

          case 'radio':
            json[name] = {
              value: _.find(arr, {name, checked: true}).value
            };
            break;

          default:
            json[name] = {value: node.value};
            break;<commit_msg>change ref to element<commit_after>import _ from 'lodash';
import $ from 'jquery';
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import META from 'src/utils/Meta';

export default class Form extends Component {
  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    settings: PropTypes.object,
  };

  componentDidMount() {
    this.element = $(this.refs.element);
    this.element.form(this.props.settings);
  }

  componentWillUnmount() {
    this.element.off();
  }

  plugin() {
    return this.element.form(...arguments);
  }

  serializeJson = () => {
    const form = this.refs.element;
    const json = {};

    _.each(['input', 'textarea', 'select'], (tag) => {
      _.each(form.getElementsByTagName(tag), (node, index, arr) => {
        const name = node.getAttribute('name');

        switch (node.getAttribute('type')) {
          case 'checkbox':
            json[name] = {checked: node.checked};
            break;

          case 'radio':
            json[name] = {
              value: _.find(arr, {name, checked: true}).value
            };
            break;

          default:
            json[name] = {value: node.value};
            break;
{'fraction_non_alphanumeric': 0.14673692744223754, 'fraction_numerical': 0.0, 'mean_word_length': 2.418282548476454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5690692', 'n_tokens_mistral': 728, 'n_tokens_neox': 710, 'n_words': 166}