"Int", "MinLength" => "Int", "MaxLength" => "Int", "Rows" => "Int" ); public static $size = 32; public static $min_length = 1; public static $max_length = 32; public static $rows = 1; static $singular_name = 'Text field'; static $plural_name = 'Text fields'; function __construct( $record = null, $isSingleton = false ) { $this->Size = self::$size; $this->MinLength = self::$min_length; $this->MaxLength = self::$max_length; $this->Rows = self::$rows; parent::__construct( $record, $isSingleton ); } function ExtraOptions() { // eventually replace hard-coded "Fields"? $baseName = "Fields[$this->ID]"; $extraFields = new FieldSet( new TextField($baseName . "[Size]", _t('EditableTextField.TEXTBOXLENGTH', 'Length of text box'), (string)$this->Size), new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'), new TextField($baseName . "[MinLength]", "", (string)$this->MinLength), new TextField($baseName . "[MaxLength]", " - ", (string)$this->MaxLength) ), new TextField($baseName . "[Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), (string)$this->Rows) ); foreach( parent::ExtraOptions() as $extraField ) $extraFields->push( $extraField ); if( $this->readonly ) $extraFields = $extraFields->makeReadonly(); return $extraFields; } function populateFromPostData( $data ) { $this->Size = !empty( $data['Size'] ) ? $data['Size'] : self::$size; $this->MinLength = !empty( $data['MinLength'] ) ? $data['MinLength'] : self::$min_length; $this->MaxLength = !empty( $data['MaxLength'] ) ? $data['MaxLength'] : self::$max_length; $this->Rows = !empty( $data['Rows'] ) ? $data['Rows'] : self::$rows; parent::populateFromPostData( $data ); } function getFormField() { return $this->createField(); } function getFilterField() { return $this->createField( true ); } function createField( $asFilter = false ) { if( $this->Rows == 1 ) return new TextField( $this->Name, $this->Title, ( $asFilter ) ? "" : $this->getField('Default'), $this->MaxLength); else return new TextareaField( $this->Name, $this->Title, $this->Rows, $this->MaxLength, ( $asFilter ) ? "" : $this->getField('Default') ); } /** * Populates the default fields. */ function DefaultField() { $disabled = ($this->readonly) ? " disabled=\"disabled\"" : ''; if($this->Rows == 1){ return '
'; }else{ return '
'; } } /** * Return the validation information related to this field. This is * interrupted as a JSON object for validate plugin and used in the * PHP. * * @see http://docs.jquery.com/Plugins/Validation/Methods * @return Array */ public function getValidation() { $options = array(); if($this->MinLength) $options['minlength'] = $this->MinLength; if($this->MaxLength) $options['maxlength'] = $this->MinLength; return $options; } } ?>