Public Member Functions | Static Public Member Functions

Wt::WDateValidator Class Reference

A validator for date input. More...

#include <Wt/WDateValidator>

Inheritance diagram for Wt::WDateValidator:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 WDateValidator (WObject *parent=0)
 Creates a date validator.
 WDateValidator (const WDate &bottom, const WDate &top, WObject *parent=0)
 Creates a date validator.
 WDateValidator (const WString &format, WObject *parent=0)
 Creates a date validator.
 WDateValidator (const WString &format, const WDate &bottom, const WDate &top, WObject *parent=0)
 Creates a date validator.
void setBottom (const WDate &bottom)
 Sets the bottom of the valid date range.
const WDatebottom () const
 Returns the bottom date of the valid range.
void setTop (const WDate &top)
 Sets the top of the valid date range.
const WDatetop () const
 Returns the top date of the valid range.
void setFormat (const WString &format)
 Sets the date format used to parse date strings.
const WStringformat () const
 Returns the format string used to parse date strings.
void setFormats (const std::vector< WString > &formats)
 Sets the date formats used to parse date strings.
const std::vector< WString > & formats () const
 Returns the date formats used to parse date strings.
virtual State validate (WString &input) const
 Validates the given input.
virtual void createExtConfig (std::ostream &config) const
 Provides Ext-compatible config options for client-side validation.
void setInvalidNotADateText (const WString &text)
 Sets the message to display when the input is not a date.
WString invalidNotADateText () const
 Returns the message displayed when the input is not a date.
void setInvalidTooEarlyText (const WString &text)
 Sets the message to display when the date is earlier than bottom.
WString invalidTooEarlyText () const
 Returns the message displayed when date is too early.
void setInvalidTooLateText (const WString &text)
 Sets the message to display when the date is later than top.
WString invalidTooLateText () const
 Returns the message displayed when the date is too late.
virtual std::string javaScriptValidate () const
 Creates a Javascript object that validates the input.

Static Public Member Functions

static WDate parse (const WString &input)
 Parses a date from a string (deprecated).

Detailed Description

A validator for date input.

This validator accepts input in the given date format, and optionally checks if the date is within a given range.

The format string used for validating user input are the same as those used by WDate::fromString().

Usage example:

 Wt::WLineEdit *lineEdit = new Wt::WLineEdit(this);
 Wt::WDateValidator *validator = new Wt::WDateValidator();
 validator->setFormat("dd-MM-yyyy");
 lineEdit->setValidator(validator);
 lineEdit->setText("01-03-2008");

i18n

The strings used in the WDateValidator can be translated by overriding the default values for the following localization keys:


Constructor & Destructor Documentation

Wt::WDateValidator::WDateValidator ( WObject parent = 0 )

Creates a date validator.

The validator will accept any date of the format 'yyyy-MM-dd'.

Wt::WDateValidator::WDateValidator ( const WDate bottom,
const WDate top,
WObject parent = 0 
)

Creates a date validator.

The validator will accept dates in the indicated range in the format 'yyyy-MM-dd'.

Wt::WDateValidator::WDateValidator ( const WString format,
WObject parent = 0 
)

Creates a date validator.

The validator will accept dates in the date format format.

The syntax for format is as in WDate::fromString()

Wt::WDateValidator::WDateValidator ( const WString format,
const WDate bottom,
const WDate top,
WObject parent = 0 
)

Creates a date validator.

The validator will accept only dates within the indicated range bottom to top, in the date format format.

The syntax for format is as in WDate::fromString()


Member Function Documentation

const WString& Wt::WDateValidator::format (  ) const

Returns the format string used to parse date strings.

See also:
setFormat()
WString Wt::WDateValidator::invalidNotADateText (  ) const

Returns the message displayed when the input is not a date.

See also:
setInvalidNotADateText(const WString&)
WString Wt::WDateValidator::invalidTooEarlyText (  ) const

Returns the message displayed when date is too early.

See also:
setInvalidTooEarlyText(const WString&)
WString Wt::WDateValidator::invalidTooLateText (  ) const

Returns the message displayed when the date is too late.

See also:
setInvalidTooLateText(const WString&)
std::string Wt::WDateValidator::javaScriptValidate (  ) const [virtual]

Creates a Javascript object that validates the input.

The JavaScript expression should evaluate to an object which contains a validate(text) function, which returns an object that contains the following two fields:

  • fields: a boolean valid,
  • a message that indicates the problem if not valid.

Return an empty string if you are not provide the client-side validation.

Note:
The signature and contract changed changed in Wt 3.1.9.
See also:
inputFilter()

Reimplemented from Wt::WValidator.

WDate Wt::WDateValidator::parse ( const WString input ) [static]

Parses a date from a string (deprecated).

Deprecated:
see WDate::fromString() static methods.

Equivalent to WDate::fromString(input, "yyyy-MM-dd");

void Wt::WDateValidator::setBottom ( const WDate bottom )

Sets the bottom of the valid date range.

The default is a null date constructed using WDate().

void Wt::WDateValidator::setFormat ( const WString format )

Sets the date format used to parse date strings.

See also:
WDate::fromString()
void Wt::WDateValidator::setInvalidNotADateText ( const WString text )

Sets the message to display when the input is not a date.

The default message is "The date must be of the format {1}", with as first argument the format string.

void Wt::WDateValidator::setInvalidTooEarlyText ( const WString text )

Sets the message to display when the date is earlier than bottom.

Depending on whether bottom() and top() are defined (see WDate::isNull()), the default message is "The date must be between {1} and {2}" or "The date must be after {1}".

void Wt::WDateValidator::setInvalidTooLateText ( const WString text )

Sets the message to display when the date is later than top.

Depending on whether bottom() and top() are defined, the default message is "The date must be between {1} and {2}" or "The date must be before {2}".

void Wt::WDateValidator::setTop ( const WDate top )

Sets the top of the valid date range.

The default is a null date constructed using WDate().

WValidator::State Wt::WDateValidator::validate ( WString input ) const [virtual]

Validates the given input.

The input is considered valid only when it is blank for a non-mandatory field, or represents a date in the given format, and within the valid range.

Reimplemented from Wt::WValidator.

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Jul 8 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2