<commit_before>//var React = require('react');
import React from 'react';
var utils = require('./utils');

const defaultValue = (props) => {
    // check if there is a value in the model, if there is, display it. Otherwise, check if
    // there is a default value, display it.
    // console.log('Text.defaultValue key', this.props.form.key);
    // console.log('Text.defaultValue model', this.props.model);
    let value;
    if (props.form && props.form.key)
        value = utils.selectOrSet(props.form.key, props.model);
    //console.log('Text defaultValue value = ', value);

    // check if there is a default value
    if (!value && props.form['default']) {
        value = props.form['default'];
    }

    if (!value && props.form.schema && props.form.schema['default']) {
        value = props.form.schema['default'];
    }
    return value;
};

export default (ComposedComponent, defaultProps = {}) => class Composed extends React.Component {

    constructor(props) {
        super(props);
        this.onChangeValidate = this.onChangeValidate.bind(this);
        let value = defaultValue(this.props);
        let validationResult = utils.validate(this.props.form, value);
        this.state = {
            value: value,
            valid: !!(validationResult.valid || !value),
            error: !validationResult.valid && (value ? validationResult.error.message : null) || this.props.errorText
        };<commit_msg>ComposedComponent: set default value if value is undefined or null<commit_after>//var React = require('react');
import React from 'react';
var utils = require('./utils');

const defaultValue = (props) => {
    // check if there is a value in the model, if there is, display it. Otherwise, check if
    // there is a default value, display it.
    // console.log('Text.defaultValue key', this.props.form.key);
    // console.log('Text.defaultValue model', this.props.model);
    let value;
    if (props.form && props.form.key)
        value = utils.selectOrSet(props.form.key, props.model);
    //console.log('Text defaultValue value = ', value);

    // check if there is a default value
    if (value === null || value === undefined) {
        if (props.form['default']) {
            value = props.form['default'];
        } else if (props.form.schema && props.form.schema['default']) {
            value = props.form.schema['default'];
        }
    }
    return value;
};

export default (ComposedComponent, defaultProps = {}) => class Composed extends React.Component {

    constructor(props) {
        super(props);
        this.onChangeValidate = this.onChangeValidate.bind(this);
        let value = defaultValue(this.props);
        let validationResult = utils.validate(this.props.form, value);
        this.state = {
            value: value,
            valid: !!(validationResult.valid || !value),
            error: !validationResult.valid && (value ? validationResult.error.message : null) || this.props.errorText
        };
{'fraction_non_alphanumeric': 0.14156018829858777, 'fraction_numerical': 0.0, 'mean_word_length': 2.794642857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1040817', 'n_tokens_mistral': 815, 'n_tokens_neox': 821, 'n_words': 225}