當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TextField::setMaxLength方法代碼示例

本文整理匯總了PHP中TextField::setMaxLength方法的典型用法代碼示例。如果您正苦於以下問題:PHP TextField::setMaxLength方法的具體用法?PHP TextField::setMaxLength怎麽用?PHP TextField::setMaxLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TextField的用法示例。


在下文中一共展示了TextField::setMaxLength方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testMaxLengthValidationSuccess

 /**
  * 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);
 }
開發者ID:ivoba,項目名稱:silverstripe-framework,代碼行數:12,代碼來源:TextFieldTest.php

示例2: getFieldsForImage

	/**
	 * @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;
	}
開發者ID:redema,項目名稱:sapphire,代碼行數:67,代碼來源:HtmlEditorField.php


注:本文中的TextField::setMaxLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。