PHP Class 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}.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends TLabel, implements Prado\Web\UI\IValidator
Afficher le fichier Open project: pradosoft/prado Class Usage Examples

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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.

Private Methods

Méthode Description
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.

Method Details

__construct() public méthode

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

addAttributesToRender() protected méthode

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

createClientSide() protected méthode

protected createClientSide ( ) : TValidatorClientSide
Résultat TValidatorClientSide javascript validator event options.

evaluateIsValid() abstract protected méthode

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

getClientClassName() abstract protected méthode

This method overrides the parent implementation.
abstract protected getClientClassName ( ) : string
Résultat string the javascript class name

getClientScriptOptions() protected méthode

Returns an array of javascript validator options.
protected getClientScriptOptions ( ) : array
Résultat array javascript validator options.

getClientSide() public méthode

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
Résultat TValidatorClientSide javascript validator event options.

getControlCssClass() public méthode

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

getControlToValidate() public méthode

public getControlToValidate ( ) : string
Résultat string the ID path of the input control to validate

getDisplay() public méthode

public getDisplay ( ) : TValidatorDisplayStyle
Résultat TValidatorDisplayStyle the style of displaying the error message. Defaults to TValidatorDisplayStyle::Fixed.

getEnableClientScript() public méthode

public getEnableClientScript ( ) : boolean
Résultat boolean whether client-side validation is enabled.

getErrorMessage() public méthode

public getErrorMessage ( ) : string
Résultat string the text for the error message.

getFocusElementID() public méthode

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

getFocusOnError() public méthode

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

getIsValid() public méthode

public getIsValid ( ) : boolean
Résultat boolean whether the validation succeeds

getValidationGroup() public méthode

public getValidationGroup ( ) : string
Résultat string the group which this validator belongs to

getValidationTarget() public méthode

public getValidationTarget ( ) : TControl
Résultat TControl control to be validated. Null if no control is found.

getValidationValue() protected méthode

Retrieves the property value of the control being validated.
protected getValidationValue ( $control ) : string
Résultat string property value to be validated

onInit() public méthode

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

onPreRender() public méthode

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

onUnload() public méthode

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

onValidate() public méthode

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() public méthode

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

onValidationSuccess() public méthode

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

registerClientScriptValidator() protected méthode

Registers the individual validator client-side javascript code.

renderClientControlScript() public méthode

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

renderContents() public méthode

Renders the validator control.
public renderContents ( $writer )

setControlCssClass() public méthode

public setControlCssClass ( $value )

setControlToValidate() public méthode

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 méthode

public setDisplay ( $value )

setEnableClientScript() public méthode

public setEnableClientScript ( $value )

setEnabled() public méthode

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

setErrorMessage() public méthode

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

setFocusElementID() public méthode

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 méthode

public setFocusOnError ( $value )

setForControl() public méthode

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

setIsValid() public méthode

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

setValidationGroup() public méthode

public setValidationGroup ( $value )

updateControlCssClass() protected méthode

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

validate() public méthode

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