<commit_before><?php
/**
 *
 */

class FormIOField_Autocomplete extends FormIOField_Text
{
	public $buildString = '<div class="row{$alt? alt}{$classes? $classes}">
		<label for="{$id}">{$desc}{$required? <span class="required">*</span>}</label>
		<input type="hidden" name="{$name}"{$value? value="$value"}{$extradata? data-fio-value-metadata="$extradata"} />
		<input type="text" name="{$friendlyName}" id="{$id}"{$result_key data-fio-display-key="$result_key"}{$friendlyValue? value="$friendlyValue"}{$readonly? readonly="readonly"}{$maxlen? maxlength="$maxlen"}{$behaviour? data-fio-type="$behaviour"}{$validation? data-fio-validation="$validation"} data-fio-searchurl="{$searchurl}"{$multiple? data-fio-multiple="$multiple"}{$delimiter? data-fio-delimiter="$delimiter"}{$dependencies? data-fio-depends="$dependencies"} />
		{$error?<p class="err">$error</p>}
		{$hint? <p class="hint">$hint</p>}
	</div>';

	const DEFAULT_DELIM = ',';

	/**
	 * Set the URL which returns JSON data for our request
	 * @param string $url url to load autocomplete results from, passed to jquery UI
	 */
	public function setAutocompleteUrl($url)
	{
		$this->setAttribute('searchurl', $url);
	}

	/**
	 * sets this input to receive multiple values, separated by a delimiter of some sort
	 * @param string $delim delimiter for separating values
	 */
	public function setMultiple($delim = ',')
	{
		$this->multiple = true;
		$this->setAttribute('multiple', '1');
		$this->setAttribute('delimiter', $delim);
	}

	public function setSingle()
	{
		$this->multiple = false;
		$this->clearAttribute('multiple');
	}

	/**
	 * override in child classes to set friendly value as appropriate for internal autocomplete workings
	 * @param array/string $value new value for the field
	 */
	public function setValue($value)
	{
		if (!is_array($value)) {
			// filter out empty entries in the list
			$value = $this->getValue($value);
		}

		parent::setValue(implode($this->getAttribute('delimiter', self::DEFAULT_DELIM), $value));
	}

	/**
	 * Overridden to concatenate if array is stored internally
	 */
	public function getHumanReadableValue()
	{
		$val = $this->getValue();
		return implode($this->getAttribute('delimiter', self::DEFAULT_DELIM), $val);
	}

	public function getValue($val = null)
	{
		if (!isset($val)) $val = parent::getValue();

		if (!$this->getAttribute('multiple', false)) {
			return $val;
		}
<commit_msg>no need to coerce values when assigned to autocomplete fields<commit_after><?php
/**
 *
 */

class FormIOField_Autocomplete extends FormIOField_Text
{
	public $buildString = '<div class="row{$alt? alt}{$classes? $classes}">
		<label for="{$id}">{$desc}{$required? <span class="required">*</span>}</label>
		<input type="hidden" name="{$name}"{$value? value="$value"}{$extradata? data-fio-value-metadata="$extradata"} />
		<input type="text" name="{$friendlyName}" id="{$id}"{$result_key data-fio-display-key="$result_key"}{$friendlyValue? value="$friendlyValue"}{$readonly? readonly="readonly"}{$maxlen? maxlength="$maxlen"}{$behaviour? data-fio-type="$behaviour"}{$validation? data-fio-validation="$validation"} data-fio-searchurl="{$searchurl}"{$multiple? data-fio-multiple="$multiple"}{$delimiter? data-fio-delimiter="$delimiter"}{$dependencies? data-fio-depends="$dependencies"} />
		{$error?<p class="err">$error</p>}
		{$hint? <p class="hint">$hint</p>}
	</div>';

	const DEFAULT_DELIM = ',';

	/**
	 * Set the URL which returns JSON data for our request
	 * @param string $url url to load autocomplete results from, passed to jquery UI
	 */
	public function setAutocompleteUrl($url)
	{
		$this->setAttribute('searchurl', $url);
	}

	/**
	 * sets this input to receive multiple values, separated by a delimiter of some sort
	 * @param string $delim delimiter for separating values
	 */
	public function setMultiple($delim = ',')
	{
		$this->multiple = true;
		$this->setAttribute('multiple', '1');
		$this->setAttribute('delimiter', $delim);
	}

	public function setSingle()
	{
		$this->multiple = false;
		$this->clearAttribute('multiple');
	}

	/**
	 * Overridden to concatenate if array is stored internally
	 */
	public function getHumanReadableValue()
	{
		$val = $this->getValue();
		return is_array($val) ? implode($this->getAttribute('delimiter', self::DEFAULT_DELIM), $val) : $val;
	}

	public function getValue($val = null)
	{
		if (!isset($val)) $val = parent::getValue();

		if (!$this->getAttribute('multiple', false)) {
			return $val;
		}

{'fraction_non_alphanumeric': 0.1858744394618834, 'fraction_numerical': 0.0004484304932735426, 'mean_word_length': 5.484011627906977, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 47, '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': '7380128', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1388, 'n_words': 322}