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 TPage::validate(). The input control to be validated is specified by \Prado\Web\UI\WebControls\setControlToValidate.
Validator controls always validate the associated input control on the serve side. In addition, if \Prado\Web\UI\WebControls\getEnableClientScript 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 TRequiredFieldValidator to ensure the input of username and a TRegularExpressionValidator to ensure the proper input.
If an input control fails validation, the text specified by the \Prado\Web\UI\WebControls\setErrorMessage property is displayed in the validation control. However, if the \Prado\Web\UI\WebControls\setText property is set, it will be displayed instead. If both \Prado\Web\UI\WebControls\setErrorMessage and \Prado\Web\UI\WebControls\setText are empty, the body content of the validator will be displayed. Error display is controlled by \Prado\Web\UI\WebControls\setDisplay property.
You can also customized the client-side behaviour by adding javascript code to the subproperties of the \Prado\Web\UI\WebControls\getClientSide property. See quickstart documentation for further details.
You can also place a TValidationSummary control on a page to display error messages from the validators together. In this case, only the \Prado\Web\UI\WebControls\setErrorMessage property of the validators will be displayed in the TValidationSummary control.
Validators can be partitioned into validation groups by setting their \Prado\Web\UI\WebControls\setValidationGroup 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 \Prado\Web\UI\TPage::getIsValid property of the current TPage instance will be automatically updated by the validation process which occurs after \Prado\Web\UI\TPage::onLoad of TPage and before the postback events. Therefore, if you use the TPage::getIsValid() property in the TPage::onLoad() method, you must first explicitly call the TPage::validate() method.
Notes to Inheritors When you inherit from TBaseValidator, you must override the method evaluateIsValid.
Class hierarchy
- \Prado\Web\UI\WebControls\TBaseValidator implements IValidator
- \Prado\Web\UI\WebControls\TLabel implements IDataRenderer
- \Prado\Web\UI\WebControls\TWebControl implements IStyleable
- \Prado\Web\UI\TControl implements IRenderable, IBindable
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
|
public
|
getClientSide() : TValidatorClientSide
Gets the TValidatorClientSide that allows modification of the client-
side validator events.
The client-side validator supports the following events. OnValidate -- raised before client-side validation isexecuted. OnValidationSuccess -- raised after client-side validation is completedand is successfull, overrides default validator error messages updates. OnValidationError -- raised after client-side validation is completedand failed, overrides default validator error message updates. You can attach custom javascript code to each of these events |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getFocusElementID() : string
Gets the ID of the HTML element that will receive focus if validation fails and {@see getFocusOnError FocusOnError} is true.
Defaults to the client ID of the \Prado\Web\UI\WebControls\getControlToValidate. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
onPreRender(mixed $param) : mixed
Override parent implementation to update the control CSS Class before
the validated control is rendered
|
public
|
|
public
|
onValidate() : mixed
This event is raised right before the validator starts to perform validation.
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
|
|
public
|
|
public
|
renderClientControlScript(THtmlWriter $writer) : mixed
Renders the javascript code to the end script.
If you override this method, be sure to call the parent implementation so that the event handlers can be invoked. |
public
|
|
public
|
|
public
|
setControlToValidate(string $value) : mixed
Sets the ID path of the input control to validate.
The ID path is the dot-connected IDs of the controls reaching from the validator's naming container to the target control. |
public
|
|
public
|
|
public
|
setEnabled(bool $value) : mixed
This method overrides parent's implementation by setting {@see setIsValid IsValid} to true if disabled.
|
public
|
|
public
|
setFocusElementID(string $value) : mixed
Sets the ID of the HTML element that will receive focus if validation fails and {@see getFocusOnError FocusOnError} is true.
|
public
|
|
public
|
setForControl(string $value) : mixed
This method overrides the parent implementation to forbid setting ForControl.
|
public
|
|
public
|
|
public
|
validate() : bool
Validates the specified control.
Do not override this method. Override evaluateIsValid instead. |
protected
|
addAttributesToRender(THtmlWriter $writer) : mixed
Adds attributes to renderer. Calls parent implementation and renders the
client control scripts.
|
protected
|
|
protected
abstract
|
evaluateIsValid() : bool
This is the major method for validation.
Derived classes should implement this method to provide customized validation. |
protected
abstract
|
getClientClassName() : string
Gets the name of the javascript class responsible for performing validation for this control.
This method overrides the parent implementation. |
protected
|
getClientScriptOptions() : array<string|int, mixed>
Returns an array of javascript validator options.
|
protected
|
getValidationValue(TControl $control) : string
Retrieves the property value of the control being validated.
|
protected
|
registerClientScriptValidator() : mixed
Registers the individual validator client-side javascript code.
|
protected
|
updateControlCssClass() : mixed
Update the ControlToValidate component's css class depending
if the ControlCssClass property is set, and whether this is valid.
|
private
|
getClientControlClass(TControl $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.
|