API Remove AjaxUniqueTextField, since its operation is very limited (#1947)

It used to validate via ajax, but that has been removed as part
of the 3.0 refactor of all prototype.js code. In the end,
its a field which is quite trivial to implement in custom code
(or in controller code), unless we re-add the Ajax features.
And I think an ajax-validating uniqueness field is too much
of an edge case to belong into core.
This commit is contained in:
Ingo Schommer 2013-05-22 16:26:30 +02:00
parent e48cdb676b
commit cb1f95e51e

View File

@ -1,69 +0,0 @@
<?php
/**
* Text field that automatically checks that the value entered is unique for the given
* set of fields in a given set of tables
* @package forms
* @subpackage fields-formattedinput
*/
class AjaxUniqueTextField extends TextField {
protected $restrictedField;
protected $restrictedTable;
// protected $restrictedMessage;
protected $validateURL;
protected $restrictedRegex;
public function __construct($name, $title, $restrictedField, $restrictedTable, $value = "", $maxLength = null,
$validationURL = null, $restrictedRegex = null ){
$this->maxLength = $maxLength;
$this->restrictedField = $restrictedField;
$this->restrictedTable = $restrictedTable;
$this->validateURL = $validationURL;
$this->restrictedRegex = $restrictedRegex;
parent::__construct($name, $title, $value);
}
public function Field($properties = array()) {
$url = Convert::raw2att( $this->validateURL );
if($this->restrictedRegex)
$restrict = "<input type=\"hidden\" class=\"hidden\" name=\"{$this->name}Restricted\" id=\"" . $this->id()
. "RestrictedRegex\" value=\"{$this->restrictedRegex}\" />";
$attributes = array(
'type' => 'text',
'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->getName(),
'value' => $this->Value(),
'tabindex' => $this->getAttribute('tabindex'),
'maxlength' => ($this->maxLength) ? $this->maxLength : null
);
return FormField::create_tag('input', $attributes);
}
public function validate( $validator ) {
$result = DB::query(sprintf(
"SELECT COUNT(*) FROM \"%s\" WHERE \"%s\" = '%s'",
$this->restrictedTable,
$this->restrictedField,
Convert::raw2sql($this->value)
))->value();
if( $result && ( $result > 0 ) ) {
$validator->validationError($this->name,
_t('Form.VALIDATIONNOTUNIQUE', "The value entered is not unique"));
return false;
}
return true;
}
}