1 <?php
2 3 4 5 6 7 8
9 class UniqueTextField extends TextField {
10
11 protected $restrictedField;
12 protected $restrictedTable;
13 protected $restrictedMessage;
14
15 function __construct($name, $restrictedField, $restrictedTable, $restrictedMessage, $title = null, $value = "", $maxLength = null ){
16 parent::__construct($name, $title, $value, $maxLength);
17
18 $this->restrictedField = $restrictedField;
19
20 $this->restrictedTable = $restrictedTable;
21 $this->restrictedMessage = $restrictedMessage;
22 }
23
24 function Field() {
25 Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
26 Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js");
27
28 $attributes = array(
29 'type' => 'text',
30 'class' => 'text ' . $this->class . ($this->extraClass() ? $this->extraClass() : ''),
31 'id' => $this->id(),
32 'name' => $this->Name(),
33 'value' => $this->attrValue(),
34 'tabindex' => $this->getTabIndex(),
35 'maxlength' => ($this->maxLength) ? $this->maxLength : null,
36 'size' => ($this->maxLength) ? min( $this->maxLength, 60 ) : 30
37 );
38
39 if($this->disabled) $attributes['disabled'] = 'disabled';
40
41 return
42 $this->createTag('input', $attributes)
43 . '<input type="hidden" name="restricted-messages['.$this->id().']" id="'.$this->id().'-restricted-message" value="'.$this->restrictedMessage.'" />'
44 ;
45 }
46 }
47 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-