Validator
Since: BlackBerry 10.1.0
#include <bb/cascades/Validator>
A default validation class that's used to validate some controls (currently, only TextField is supported).
Validator includes the following properties:
state: Specifies the current validation state. This property shows the current ValidationState of the control. Controls can listen to changes to this property to respond to state changes.
mode: Specifies the current validation mode. This property configures the validator's scheduling logic.
valid: Specifies the current validity of the Control. This property can be used to set a Validator to a Valid or Invalid state. Controls can listen to changes to this property to respond to state changes if some specific actions must be performed when the state changes to a Valid or Invalid state. For example, if the Control should show an error when the validation state is changed to Invalid. When the valid property changes, the state property changes also.
errorMessage: Specifies the error message. This property contains a text representation of the error in an Invalid state.
The following sample demonstrates how to validate a TextField in C++. The code below assumes that ValidatePasswordApplication has the onValidate() slot.
ValidatePasswordApplication::ValidatePasswordApplication() { TextField* passwordField = TextField::create().hintText("Password"); passwordField.setValidator( Validator::create() .errorMessage("Incorrect password") .mode(ValidationMode::FocusLost)) .connect(SIGNAL(validate()), this, SLOT(onValidate())); }
Here's how to validate a TextField in QML:
TextField { id: passwordField validator: Validator { mode: ValidationMode.FocusLost errorMessage: "Invalid password" onValidate: { // validate a passwordField's text and set appropriate state. } } }
Overview
Inheritance
bb::cascades::BaseObject | ||
bb::cascades::Validator |
QML properties
delay | : int |
errorMessage | : QString |
mode | : bb::cascades::ValidationMode::Type |
state | : bb::cascades::ValidationState::Type |
valid | : bool |
validationRequested | : bool |
objectName | : QString![]() |
parent | : QObject [read-only]![]() |
QML signals
Public Types Index
Properties Index
Public Functions Index
Validator (QObject *parent=0) | |
virtual | ~Validator () |
int | delay () const |
QString | errorMessage () const |
bool | isValid () const |
bb::cascades::ValidationMode::Type | mode () const |
Q_SLOT void | requestValidation () |
Q_INVOKABLE void | resetDelay () |
Q_INVOKABLE void | resetErrorMessage () |
Q_INVOKABLE void | resetMode () |
Q_INVOKABLE void | resetState () |
Q_INVOKABLE void | resetValid () |
Q_INVOKABLE void | resetValidationRequested () |
Q_SLOT void | setDelay (int delay) |
Q_SLOT void | setErrorMessage (const QString &errorMessage) |
Q_SLOT void | setMode (bb::cascades::ValidationMode::Type mode) |
Q_SLOT void | setState (bb::cascades::ValidationState::Type state) |
Q_SLOT void | setValid (bool valid) |
Q_SLOT void | setValidationRequested (bool requested) |
Q_SLOT void | showMessage () |
bb::cascades::ValidationState::Type | state () const |
bool | validationRequested () const |
void | setObjectName (const QString &name)![]() |
virtual Q_INVOKABLE QString | toDebugString () const ![]() |
Static Public Functions Index
Builder | create () |
Protected Functions Index
Only has inherited protected functions
BaseObject (QObject *parent=0)![]() |
Signals Index
void | delayChanged (int delay) |
void | errorMessageChanged (const QString errorMessage) |
void | modeChanged (bb::cascades::ValidationMode::Type newMode) |
void | stateChanged (bb::cascades::ValidationState::Type newState) |
void | validate () |
void | validationRequestedChanged (bool requested) |
void | validChanged (bool valid) |
void | creationCompleted ()![]() |
void | objectNameChanged (const QString &objectName)![]() |
Public Types
typedef BaseObject
Properties
int
Represents a delay in milliseconds.
BlackBerry 10.1.0
QString
Represents the error message.
Contains an error message for the invalid validation state.
The default value is QString::null.
BlackBerry 10.1.0
bb::cascades::ValidationMode::Type
The validation mode.
Validation mode as defined in ValidationMode.
The default value is ValidationMode::Default.
BlackBerry 10.1.0
bb::cascades::ValidationState::Type
The validation state.
Validation state as defined in ValidationState.
The default value is ValidationState::Unknown.
BlackBerry 10.1.0
bool
Represents whether validation was successful or not.
Returns true if the state property is in a Valid state or no validation was performed yet, false otherwise. This property is bound with the state property. If the state changes to ValidationState::Valid, the valid property will be true. If the state changes to ValidationState::Invalid, the valid property will be false.
If the state property changes to ValidationState::Unknown or ValidationState::InProgress, then the valid property will not change.
BlackBerry 10.1.0
bool
Represents whether validation was requested or not.
If this property is set to true then requestValidation will be called. When the validate signal is emitted this property would set back to false.
If the mode is set to ValidationMode::Custom, you can listen to this property to find out when validation has been requested. You are responsible for calling validate and resetting the validationRequested property back to false.
BlackBerry 10.1.0
QString
This property is overridden from QObject.
QObject::objectName().
BlackBerry 10.0.0
QObject
A read-only property that represents this object's parent.
The parent of an object is specified using QObject::setParent(QObject*). The purpose of the property is to expose the object's parent to QML.
This property is read-only to prevent modifications from QML, where typically the parent is declaratively set. In C++ code, the parent can be explicitly set using QObject::setParent(QObject*), or implicitly set by adding it to a visual container.
The default value of this property is 0.
BlackBerry 10.0.0
Public Functions
virtual
Destructor.
QString
Returns the errorMessage text.
The error message text. Returns an empty string if it is not set.
BlackBerry 10.1.0
bool
Returns the valid value.
The valid value. The default value is false.
BlackBerry 10.1.0
bb::cascades::ValidationMode::Type
Returns the validation mode.
The validation mode. ValidationMode::Default by default.
BlackBerry 10.1.0
Q_SLOT void
Requests a re-validation of the source according to the mode property.
The validate signal is emitted directly from this slot or with a delay, depending on the mode property. If mode is set to ValidationMode::Custom the validate signal is not emitted.
BlackBerry 10.1.0
Q_INVOKABLE void
Resets valid to its default value.
Also resets the state to its default value.
BlackBerry 10.1.0
Q_INVOKABLE void
Resets the validationRequested to its default value of false.
BlackBerry 10.1.0
Q_SLOT void
Sets the delay in milliseconds.
Parameters | |
---|---|
delay |
The delay in milliseconds. |
BlackBerry 10.1.0
Q_SLOT void
Sets the error message text.
Parameters | |
---|---|
errorMessage |
The error message text. |
BlackBerry 10.1.0
Q_SLOT void
Sets the validation mode.
Parameters | |
---|---|
mode |
The validation mode. |
BlackBerry 10.1.0
Q_SLOT void
Sets the validation state.
Parameters | |
---|---|
state |
The validation state. |
BlackBerry 10.1.0
Q_SLOT void
Sets the valid property.
Parameters | |
---|---|
valid |
Boolean value. |
BlackBerry 10.1.0
Q_SLOT void
Sets the validationRequested property.
Parameters | |
---|---|
requested |
Boolean value. |
BlackBerry 10.1.0
Q_SLOT void
Shows a toast message with errorMessage text.
BlackBerry 10.1.0
bb::cascades::ValidationState::Type
Returns the validation state.
The validation state. ValidationState::Unknown by default.
BlackBerry 10.1.0
bool
Returns the validationRequested value.
The validationRequested value. The default value is false.
BlackBerry 10.1.0
void 
Sets the objectName property.
Parameters | |
---|---|
name |
The new name for the object. |
BlackBerry 10.0.0
virtual Q_INVOKABLE QString 
Returns a debug string representing this object.
A debug string for the object.
BlackBerry 10.0.0
Static Public Functions
Builder
Creates and returns a builder for constructing a Validator.
The following sample uses the builder to create a Validator:
Validator* validator = Validator::create();
A builder used for constructing a Validator.
BlackBerry 10.1.0
Protected Functions
(Only has inherited protected functions)
Constructs an instance of BaseObject's subclass.
Parameters | |
---|---|
parent |
An optional parent, defaults to 0. |
BlackBerry 10.0.0
Signals
void
Emitted when the delay property changes.
Parameters | |
---|---|
delay |
The new delay in milliseconds. |
BlackBerry 10.1.0
void
Emitted when the error message text changes.
Parameters | |
---|---|
errorMessage |
The new error message text. |
BlackBerry 10.1.0
void
Emitted when the validation mode changes.
Parameters | |
---|---|
newMode |
The new validation mode. |
BlackBerry 10.1.0
void
Emitted when the validation state changes.
Parameters | |
---|---|
newState |
The new validation state. |
BlackBerry 10.1.0
void
Emitted when validation should be performed by the client.
BlackBerry 10.1.0
void
Emitted when the validationRequested property changes.
Parameters | |
---|---|
requested |
The new validationRequested property value. |
BlackBerry 10.1.0
void
Emitted when the valid property changes.
Parameters | |
---|---|
valid |
The new valid property value. |
BlackBerry 10.1.0
void 
Emitted when this object is instantiated as a result of loading a QML document and creating the root node (only after the root component that caused this instantiation has completed construction), or when the object is being constructed from its builder class.
This signal indicates that the construction and initialization of the object has been completed, the properties are initialized, and any QML binding values have been assigned to the object.
This signal is not emitted when the object is constructed from C++ using the constructor. If the object is constructed using its builder class, the signal is emitted when the the builder class returns the fully constructed object.
This signal can be used when there is an activity that needs to be performed, such as a property state integrity verification after the object is instantiated from a QML document or a builder, but before control is returned to the application.
BlackBerry 10.0.0
void 
This signal is emitted when the objectName property is changed.
BlackBerry 10.0.0