<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package fusionLib
 * @copyright Copyright (c) 2007 - 2013 fusionLib. All rights reserved.
 * @link http://fusionlib.com
 */

/**
 * flFormElementText Class
 *
 * Single line text input form element.
 *
 * @package fusionLib
 */
class flFormElementText extends flFormElement {
	/**
	 * The maximum input length.
	 *
	 * @var int
	 */
	protected $maxLength = null;

	/**
	 * Set the maximum input length.
	 *
	 * @param int $length The max input length.
	 * @return flFormElementText This object.
	 */
	function setMaxLength($length) {
		$this->maxLength = $length;
		return $this;
	}

	/**
	 * Switch off autocomplete for the element.
	 *
	 * @param bool $off true to turn autocomplete off; else false.
	 * @return flFormElementText This object.
	 */
	function autocompleteOff($off = true) {
		$this->autocomplete = $off ? 'off' : 'on';
		return $this;
	}

	/**
	 * Draw the element.
	 *
	 * @return string Element HTML.
	 */
	function render() {
		$html = "<input type=\"text\" id=\"$this->name\" name=\"$this->name\" value=\"" . $this->_getValueEscaped() . '"';
		if($this->maxLength !== null) $html .= " maxlength=\"$this->maxLength\"";
		return $html . $this->attribHTML() . " />\n";
	}
}
