<commit_before>var FieldType = require('../Type');
var util = require('util');
var utils = require('keystone-utils');

/**
 * TextArray FieldType Constructor
 * @extends Field
 * @api public
 */
function textarray (list, path, options) {
	this._nativeType = [String];
	textarray.super_.call(this, list, path, options);
}
util.inherits(textarray, FieldType);

/**
 * Validates that a value for this field has been provided in a data object
 *
 * Deprecated
 */
textarray.prototype.inputIsValid = function (data, required, item) {
	var value = this.getValueFromData(data);
	if (required) {
		if (value === undefined && item && item.get(this.path) && item.get(this.path).length) {
			return true;
		}
		if (value === undefined || !Array.isArray(value) || (typeof value !== 'string') || (typeof value !== 'number')) {
			return false;
		}
		if (Array.isArray(value) && !value.length) {
			return false;
		}
	}
	return (value === undefined || Array.isArray(value) || (typeof value === 'string') || (typeof value === 'number'));
};

/**
 * Updates the value for this field in the item from a data object
 */
textarray.prototype.updateItem = function (item, data, callback) {
	var value = this.getValueFromData(data);
	if (typeof value !== 'undefined') {
		if (value === null) {
			value = [];
		}
		if (typeof value === 'string') {
			value = [value];
		}
		if (typeof value === 'number') {
			value = [value.toString()];
		}
		if (Array.isArray(value)) {
			item.set(this.path, value);
		}
	}
	process.nextTick(callback);
};

/* Export Field Type */
module.exports = textarray;
<commit_msg>Adding validateInput and validateRequiredInput for textarray fields<commit_after>var FieldType = require('../Type');
var util = require('util');
var utils = require('keystone-utils');

/**
 * TextArray FieldType Constructor
 * @extends Field
 * @api public
 */
function textarray (list, path, options) {
	this._nativeType = [String];
	textarray.super_.call(this, list, path, options);
}
util.inherits(textarray, FieldType);

/**
 * Asynchronously confirms that the provided value is valid
 */
textarray.prototype.validateInput = function (data, callback) {
	var value = this.getValueFromData(data);
	var result = true;
	if (value !== undefined) {
		if (!Array.isArray(value)) {
			value = [value];
		}
		value.forEach(function (str) {
			if (typeof str !== 'string') {
				result = false;
			}
		});
	}
	utils.defer(callback, result);
};

/**
 * Asynchronously confirms that the a value is present
 */
textarray.prototype.validateRequiredInput = function (item, data, callback) {
	var value = this.getValueFromData(data);
	var result = false;
	if (value === undefined) {
		if (item.get(this.path) && item.get(this.path).length) {
			result = true;
		}
	} else if (typeof value === 'string') {
		result = true;
	} else if (Array.isArray(value)) {
		for (var i = 0; i < value.length; i++) {
			if (typeof value[i] === 'string' && value[i].length) {
				result = true;
				break;
			}
		}
	}
	utils.defer(callback, result);
};

/**
 * Validates that a value for this field has been provided in a data object
 *
 * Deprecated
 */
textarray.prototype.inputIsValid = function (data, required, item) {
	var value = this.getValueFromData(data);
	if (required) {
		if (value === undefined && item && item.get(this.path) && item.get(this.path).length) {
			return true;
		}
		if (value === undefined || !Array.isArray(value) || (typeof value !== 'string') || (typeof value !== 'number')) {
			return false;
		}
		if (Array.isArray(value) && !value.length) {
			return false;
		}
	}
	return (value === undefined || Array.isArray(value) || (typeof value === 'string') || (typeof value === 'number'));
};

/**
 * Updates the value for this field in the item from a data object
 */
textarray.prototype.updateItem = function (item, data, callback) {
	var value = this.getValueFromData(data);
	if (typeof value !== 'undefined') {
		if (value === null) {
			value = [];
		}
		if (typeof value === 'string') {
			value = [value];
		}
		if (typeof value === 'number') {
			value = [value.toString()];
		}
		if (Array.isArray(value)) {
			item.set(this.path, value);
		}
	}
	process.nextTick(callback);
};

/* Export Field Type */
module.exports = textarray;

{'fraction_non_alphanumeric': 0.16974431818181818, 'fraction_numerical': 0.00023674242424242425, 'mean_word_length': 3.8011363636363638, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '5436488', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1352, 'n_words': 375}