PHP 클래스 Prado\Web\UI\WebControls\TBaseValidator

TBaseValidator serves as the base class for validator controls. Validation is performed when a postback control, such as a TButton, a TLinkButton or a TTextBox (under AutoPostBack mode) is submitting the page and its CausesValidation property is true. You can also manually perform validation by calling {@link TPage::validate()}. The input control to be validated is specified by {@link setControlToValidate ControlToValidate}. Validator controls always validate the associated input control on the serve side. In addition, if {@link getEnableClientScript EnableClientScript} is true, validation will also be performed on the client-side using javascript. Client-side validation will validate user input before it is sent to the server. The form data will not be submitted if any error is detected. This avoids the round-trip of information necessary for server-side validation. You can use multiple validator controls to validate a single input control, each responsible for validating against a different criteria. For example, on a user registration form, you may want to make sure the user enters a value in the username text box, and the input must consist of only word characters. You can use a {@link TRequiredFieldValidator} to ensure the input of username and a {@link TRegularExpressionValidator} to ensure the proper input. If an input control fails validation, the text specified by the {@link setErrorMessage ErrorMessage} property is displayed in the validation control. However, if the {@link setText Text} property is set, it will be displayed instead. If both {@link setErrorMessage ErrorMessage} and {@link setText Text} are empty, the body content of the validator will be displayed. Error display is controlled by {@link setDisplay Display} property. You can also customized the client-side behaviour by adding javascript code to the subproperties of the {@link getClientSide ClientSide} property. See quickstart documentation for further details. You can also place a {@link TValidationSummary} control on a page to display error messages from the validators together. In this case, only the {@link setErrorMessage ErrorMessage} property of the validators will be displayed in the {@link TValidationSummary} control. Validators can be partitioned into validation groups by setting their {@link setValidationGroup ValidationGroup} property. If the control causing the validation also sets its ValidationGroup property, only those validators having the same ValidationGroup value will do input validation. Note, the {@link TPage::getIsValid IsValid} property of the current {@link TPage} instance will be automatically updated by the validation process which occurs after {@link TPage::onLoad onLoad} of {@link TPage} and before the postback events. Therefore, if you use the {@link TPage::getIsValid()} property in the {@link TPage::onLoad()} method, you must first explicitly call the {@link TPage::validate()} method. Notes to Inheritors When you inherit from TBaseValidator, you must override the method {@link evaluateIsValid}.
부터: 3.0
저자: Qiang Xue ([email protected])
상속: extends TLabel, implements Prado\Web\UI\IValidator
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( ) Constructor.
getClientSide ( ) : TValidatorClientSide Gets the TValidatorClientSide that allows modification of the client- side validator events.
getControlCssClass ( ) : string
getControlToValidate ( ) : string
getDisplay ( ) : TValidatorDisplayStyle
getEnableClientScript ( ) : boolean
getErrorMessage ( ) : string
getFocusElementID ( ) : string Gets the ID of the HTML element that will receive focus if validation fails and {@link getFocusOnError FocusOnError} is true.
getFocusOnError ( ) : boolean
getIsValid ( ) : boolean
getValidationGroup ( ) : string
getValidationTarget ( ) : TControl
onInit ( $param ) Registers the validator with page.
onPreRender ( $param ) Override parent implementation to update the control CSS Class before the validated control is rendered
onUnload ( $param ) Unregisters the validator from page.
onValidate ( ) This event is raised right before the validator starts to perform validation.
onValidationError ( ) This event is raised when the validator fails in validation.
onValidationSuccess ( ) This event is raised when the validator succeeds in validation.
renderClientControlScript ( $writer ) Renders the javascript code to the end script.
renderContents ( $writer ) Renders the validator control.
setControlCssClass ( $value )
setControlToValidate ( $value ) Sets the ID path of the input control to validate.
setDisplay ( $value )
setEnableClientScript ( $value )
setEnabled ( $value ) This method overrides parent's implementation by setting {@link setIsValid IsValid} to true if disabled.
setErrorMessage ( $value ) Sets the text for the error message.
setFocusElementID ( $value ) Sets the ID of the HTML element that will receive focus if validation fails and {@link getFocusOnError FocusOnError} is true.
setFocusOnError ( $value )
setForControl ( $value ) This method overrides the parent implementation to forbid setting ForControl.
setIsValid ( $value ) Sets the value indicating whether the validation succeeds
setValidationGroup ( $value )
validate ( ) : boolean Validates the specified control.

보호된 메소드들

메소드 설명
addAttributesToRender ( $writer ) Adds attributes to renderer. Calls parent implementation and renders the client control scripts.
createClientSide ( ) : TValidatorClientSide
evaluateIsValid ( ) : boolean This is the major method for validation.
getClientClassName ( ) : string Gets the name of the javascript class responsible for performing validation for this control.
getClientScriptOptions ( ) : array Returns an array of javascript validator options.
getValidationValue ( $control ) : string Retrieves the property value of the control being validated.
registerClientScriptValidator ( ) Registers the individual validator client-side javascript code.
updateControlCssClass ( ) : boolean Update the ControlToValidate component's css class depending if the ControlCssClass property is set, and whether this is valid.

비공개 메소드들

메소드 설명
getClientControlClass ( $control ) : string Gets the Control type for client-side validation. If new cases exists in TBaseValidator::$_clientClass, be sure to update the corresponding "Javascript/validation3.js" file as well.

메소드 상세

__construct() 공개 메소드

This method sets the foreground color to red.
public __construct ( )

addAttributesToRender() 보호된 메소드

Adds attributes to renderer. Calls parent implementation and renders the client control scripts.
protected addAttributesToRender ( $writer )

createClientSide() 보호된 메소드

protected createClientSide ( ) : TValidatorClientSide
리턴 TValidatorClientSide javascript validator event options.

evaluateIsValid() 추상적인 보호된 메소드

Derived classes should implement this method to provide customized validation.
abstract protected evaluateIsValid ( ) : boolean
리턴 boolean whether the validation succeeds

getClientClassName() 추상적인 보호된 메소드

This method overrides the parent implementation.
abstract protected getClientClassName ( ) : string
리턴 string the javascript class name

getClientScriptOptions() 보호된 메소드

Returns an array of javascript validator options.
protected getClientScriptOptions ( ) : array
리턴 array javascript validator options.

getClientSide() 공개 메소드

The client-side validator supports the following events. # OnValidate -- raised before client-side validation is executed. # OnValidationSuccess -- raised after client-side validation is completed and is successfull, overrides default validator error messages updates. # OnValidationError -- raised after client-side validation is completed and failed, overrides default validator error message updates. You can attach custom javascript code to each of these events
public getClientSide ( ) : TValidatorClientSide
리턴 TValidatorClientSide javascript validator event options.

getControlCssClass() 공개 메소드

public getControlCssClass ( ) : string
리턴 string the css class that is applied to the control being validated in case the validation fails

getControlToValidate() 공개 메소드

public getControlToValidate ( ) : string
리턴 string the ID path of the input control to validate

getDisplay() 공개 메소드

public getDisplay ( ) : TValidatorDisplayStyle
리턴 TValidatorDisplayStyle the style of displaying the error message. Defaults to TValidatorDisplayStyle::Fixed.

getEnableClientScript() 공개 메소드

public getEnableClientScript ( ) : boolean
리턴 boolean whether client-side validation is enabled.

getErrorMessage() 공개 메소드

public getErrorMessage ( ) : string
리턴 string the text for the error message.

getFocusElementID() 공개 메소드

Defaults to the client ID of the {@link getControlToValidate ControlToValidate}.
public getFocusElementID ( ) : string
리턴 string the ID of the HTML element to receive focus

getFocusOnError() 공개 메소드

public getFocusOnError ( ) : boolean
리턴 boolean whether to set focus at the validating place if the validation fails. Defaults to false.

getIsValid() 공개 메소드

public getIsValid ( ) : boolean
리턴 boolean whether the validation succeeds

getValidationGroup() 공개 메소드

public getValidationGroup ( ) : string
리턴 string the group which this validator belongs to

getValidationTarget() 공개 메소드

public getValidationTarget ( ) : TControl
리턴 TControl control to be validated. Null if no control is found.

getValidationValue() 보호된 메소드

Retrieves the property value of the control being validated.
protected getValidationValue ( $control ) : string
리턴 string property value to be validated

onInit() 공개 메소드

Registers the validator with page.
public onInit ( $param )

onPreRender() 공개 메소드

Override parent implementation to update the control CSS Class before the validated control is rendered
public onPreRender ( $param )

onUnload() 공개 메소드

Unregisters the validator from page.
public onUnload ( $param )

onValidate() 공개 메소드

You may use this event to change the behavior of validation. For example, you may disable the validator if certain condition is satisfied. Note, the event will NOT be raised if the validator is invisible.
public onValidate ( )

onValidationError() 공개 메소드

This event is raised when the validator fails in validation.
public onValidationError ( )

onValidationSuccess() 공개 메소드

This event is raised when the validator succeeds in validation.
public onValidationSuccess ( )

registerClientScriptValidator() 보호된 메소드

Registers the individual validator client-side javascript code.

renderClientControlScript() 공개 메소드

If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.
public renderClientControlScript ( $writer )

renderContents() 공개 메소드

Renders the validator control.
public renderContents ( $writer )

setControlCssClass() 공개 메소드

public setControlCssClass ( $value )

setControlToValidate() 공개 메소드

The ID path is the dot-connected IDs of the controls reaching from the validator's naming container to the target control.
public setControlToValidate ( $value )

setDisplay() 공개 메소드

public setDisplay ( $value )

setEnableClientScript() 공개 메소드

public setEnableClientScript ( $value )

setEnabled() 공개 메소드

This method overrides parent's implementation by setting {@link setIsValid IsValid} to true if disabled.
public setEnabled ( $value )

setErrorMessage() 공개 메소드

Sets the text for the error message.
public setErrorMessage ( $value )

setFocusElementID() 공개 메소드

Sets the ID of the HTML element that will receive focus if validation fails and {@link getFocusOnError FocusOnError} is true.
public setFocusElementID ( $value )

setFocusOnError() 공개 메소드

public setFocusOnError ( $value )

setForControl() 공개 메소드

This method overrides the parent implementation to forbid setting ForControl.
public setForControl ( $value )

setIsValid() 공개 메소드

Sets the value indicating whether the validation succeeds
public setIsValid ( $value )

setValidationGroup() 공개 메소드

public setValidationGroup ( $value )

updateControlCssClass() 보호된 메소드

Update the ControlToValidate component's css class depending if the ControlCssClass property is set, and whether this is valid.
protected updateControlCssClass ( ) : boolean
리턴 boolean true if change, false otherwise.

validate() 공개 메소드

Do not override this method. Override {@link evaluateIsValid} instead.
public validate ( ) : boolean
리턴 boolean whether the validation succeeds