Wt::WValidator Class Reference

A validator is used to validate user input according to pre-defined rules. More...

#include <WValidator>

Inheritance diagram for Wt::WValidator:

Inheritance graph
[legend]

List of all members.

Public Types

enum  State { Invalid, InvalidEmpty, Valid }
 The state in which validated input can exist. More...

Public Member Functions

 WValidator (bool mandatory=false)
 Create a new validator.
void setMandatory (bool how)
 Set if input is mandatory.
bool isMandatory () const
 Returns if input is mandatory.
void setInvalidBlankText (const WString &text)
 Set message to display when a mandatory field is left blank.
virtual void fixup (WString &input) const
 This function attempts to change input to be valid according to the validator's rules.
virtual State validate (WString &input, int &pos) const
 Evaluate the validness of the given input.
virtual void createExtConfig (std::ostream &config) const
 Provide Ext-compatible config options for client-side validation.


Detailed Description

A validator is used to validate user input according to pre-defined rules.

A WValidator can be associated with a WFormWidget, using WFormWidget::setValidator.

This WValidator only checks that mandatory fields are not empty. This class is reimplemented in WIntValidator, WDoubleValidator, and WRegExpValidator, which perform checks on the input as well.

If these validators are not suitable, you can inherit from this class, and provide a suitable implementation to validate() and fixup().

A validator may have a split implementation to provide both validation at the client-side (and give instant feed-back to the user editing), and server-side validation (to be sure that the client was not tampered with).

See also:
WFormWidget

WValidationStatus


Member Enumeration Documentation

enum Wt::WValidator::State

The state in which validated input can exist.

Enumerator:
Invalid  The input is invalid.
InvalidEmpty  The input is invalid (emtpy and mandatory).
Valid  The input is valid.


Constructor & Destructor Documentation

Wt::WValidator::WValidator ( bool  mandatory = false  ) 

Create a new validator.

Indicate whether input is mandatory.

See also:
setMandatory(bool)


Member Function Documentation

void Wt::WValidator::setMandatory ( bool  how  ) 

Set if input is mandatory.

When an input is not mandatory, then an empty field is always valid.

void Wt::WValidator::fixup ( WString input  )  const [virtual]

This function attempts to change input to be valid according to the validator's rules.

In general the function needs not to change the input into a valid input. The default implementation does nothing. But it may help the user in getting its input right.

WValidator::State Wt::WValidator::validate ( WString input,
int &  pos 
) const [virtual]

Evaluate the validness of the given input.

This function returns the current state of the input.

The function can change both input and pos (the cursor position) if required.

Reimplemented in Wt::WDateValidator, Wt::WDoubleValidator, Wt::WIntValidator, Wt::WLengthValidator, and Wt::WRegExpValidator.


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 15:15:01 2008 for Wt by doxygen 1.5.3