/**
  * Tests the TextField Max Length Validation Success
  */
 public function testMaxLengthValidationSuccess()
 {
     $textField = new TextField('TestField');
     $textField->setMaxLength(5);
     $textField->setValue("John");
     // 4 characters, so should pass
     $result = $textField->validate(new RequiredFields());
     $this->assertTrue($result);
 }
Пример #2
0
	/**
	 * @return FieldList
	 */
	protected function getFieldsForImage($url, $file) {
		if($file instanceof Image) {
			$formattedImage = $file->FormattedImage('SetWidth', Image::$asset_preview_width);
			$thumbnailURL = $formattedImage ? $formattedImage->URL : $url;	
		} else {
			$thumbnailURL = $url;
		}
		
		$previewField = new LiteralField("ImageFull",
			"<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnailURL}?r=" . rand(1,100000)  . "' alt='{$file->Name}' />\n"
		);

		$fields = new FieldList(
			$filePreview = CompositeField::create(
				CompositeField::create(
					$previewField
				)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
				CompositeField::create(
					CompositeField::create(
						new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':', $file->FileType),
						new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', $file->getSize()),
						$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
							sprintf('<a href="%s" target="_blank">%s</a>', $file->Link(), $file->RelativeLink())
						),
						new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':', $file->Created),
						new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed') . ':', $file->LastEdited)
					)
				)->setName("FilePreviewData")->addExtraClass('cms-file-info-data')
			)->setName("FilePreview")->addExtraClass('cms-file-info'),
			new TextField(
				'AltText', 
				_t('HtmlEditorField.IMAGEALTTEXT', 'Alternative text (alt) - shown if image cannot be displayed'), 
				$file->Title, 
				80
			),
			new TextField(
				'Title', 
				_t('HtmlEditorField.IMAGETITLE', 'Title text (tooltip) - for additional information about the image')
			),
			new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
			new DropdownField(
				'CSSClass',
				_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
				array(
					'left' => _t('HtmlEditorField.CSSCLASSLEFT', 'On the left, with text wrapping around.'),
					'leftAlone' => _t('HtmlEditorField.CSSCLASSLEFTALONE', 'On the left, on its own.'),
					'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.'),
					'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
				)
			),
			$dimensionsField = new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'),
				$widthField = new TextField('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), $file->Width),
				$heightField = new TextField('Height', " x " . _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'), $file->Height)
			)
		);
		$urlField->dontEscape = true;
		$dimensionsField->addExtraClass('dimensions');
		$widthField->setMaxLength(5);
		$heightField->setMaxLength(5);

		$this->extend('updateFieldsForImage', $fields, $url, $file);

		return $fields;
	}