Wt  4.15.0
Loading...
Searching...
No Matches
Wt::WDateTimeValidator Class Reference

A validator for dateTime input. More...

#include <Wt/WDateTimeValidator.h>

Inheritance diagram for Wt::WDateTimeValidator:
[legend]

Public Member Functions

 WDateTimeValidator ()
 Creates a datetime validator.
 WDateTimeValidator (const WDateTime &bottom, const WDateTime &top)
 Creates a datetime validator.
 WDateTimeValidator (const WString &format)
 Creates a datetime validator.
 WDateTimeValidator (const WString &format, const WDateTime &bottom, const WDateTime &top)
 Creates a datetime validator.
void setBottom (const WDateTime &bottom)
 Sets the bottom of the valid datetime range.
const WDateTime & bottom () const
 Returns the bottom datetime of the valid range.
void setTop (const WDateTime &top)
 Sets the top of the valid datetime range.
const WDateTime & top () const
 Returns the top datetime of the valid range.
void setFormat (const WString &format)
 Sets the datetime format used to parse datetime strings.
WString format () const override
 Returns the format string used to parse datetime strings.
void setFormats (const std::vector< WString > &formats)
 Sets the datetime formats used to parse datetime strings.
const std::vector< WString > & formats () const
 Returns the datetime formats used to parse datetime strings.
Result validate (const WString &input) const override
 Validates the given input.
std::string javaScriptValidate () const override
 Creates a Javascript object that validates the input.
void setInvalidNotADateTimeText (const WString &text)
 Sets the message to display when the input is not a datetime.
WString invalidNotADateTimeText () const
 Returns the message displayed when the input is not a datetime.
void setInvalidTooEarlyText (const WString &text)
 Sets the message to display when the datetime is earlier than bottom().
WString invalidTooEarlyText () const
 Returns the message displayed when datetime is too early.
void setInvalidTooLateText (const WString &text)
 Sets the message to display when the datetime is later than top().
WString invalidTooLateText () const
 Returns the message displayed when the datetime is too late.
Public Member Functions inherited from Wt::WValidator
 WValidator (bool mandatory=false)
 Creates a new validator.
virtual ~WValidator ()
 Destructor.
void setMandatory (bool how)
 Sets if input is mandatory.
bool isMandatory () const
 Returns if input is mandatory.
void setInvalidBlankText (const WString &text)
 Sets the message to display when a mandatory field is left blank.
WString invalidBlankText () const
 Returns the message displayed when a mandatory field is left blank.
virtual std::string inputFilter () const
 Returns a regular expression that filters input.

Additional Inherited Members

Public Types inherited from Wt::WValidator
typedef ValidationState State
 Typedef for enum Wt::ValidationState.

Detailed Description

A validator for dateTime input.

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

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

See also
WDateTimeEdit
WDateTime

Constructor & Destructor Documentation

◆ WDateTimeValidator() [1/4]

Wt::WDateTimeValidator::WDateTimeValidator ( )

Creates a datetime validator.

The validator will accept datetimes using the current locale's format.

◆ WDateTimeValidator() [2/4]

Wt::WDateTimeValidator::WDateTimeValidator ( const WDateTime & bottom,
const WDateTime & top )

Creates a datetime validator.

The validator will accept only datetimes within the indicated range bottom to top.

◆ WDateTimeValidator() [3/4]

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

Creates a datetime validator.

The validator will accept dates in the date format format.

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

◆ WDateTimeValidator() [4/4]

Wt::WDateTimeValidator::WDateTimeValidator ( const WString & format,
const WDateTime & bottom,
const WDateTime & top )

Creates a datetime validator.

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

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

Member Function Documentation

◆ format()

WString Wt::WDateTimeValidator::format ( ) const
overridevirtual

Returns the format string used to parse datetime strings.

If multiple formats are specified, the first format in the list is returned.

See also
setFormat()

Reimplemented from Wt::WValidator.

◆ invalidNotADateTimeText()

WString Wt::WDateTimeValidator::invalidNotADateTimeText ( ) const

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

See also
setInvalidNotADateTimeText(const WString&)

◆ invalidTooEarlyText()

WString Wt::WDateTimeValidator::invalidTooEarlyText ( ) const

Returns the message displayed when datetime is too early.

See also
setInvalidTooEarlyText(const WString&)

◆ invalidTooLateText()

WString Wt::WDateTimeValidator::invalidTooLateText ( ) const

Returns the message displayed when the datetime is too late.

See also
setInvalidTooLateText(const WString&)

◆ javaScriptValidate()

std::string Wt::WDateTimeValidator::javaScriptValidate ( ) const
overridevirtual

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.

Returns an empty string if the validator does not provide a client-side validation implementationq.

See also
inputFilter()

Reimplemented from Wt::WValidator.

◆ setBottom()

void Wt::WDateTimeValidator::setBottom ( const WDateTime & bottom)

Sets the bottom of the valid datetime range.

The default is an empty datetime constructed using WDateTime().

◆ setFormat()

void Wt::WDateTimeValidator::setFormat ( const WString & format)

Sets the datetime format used to parse datetime strings.

See also
setFormats(), WDateTime::fromString()

◆ setFormats()

void Wt::WDateTimeValidator::setFormats ( const std::vector< WString > & formats)

Sets the datetime formats used to parse datetime strings.

When multiple formats are given, the first format that correctly parses the input is used.

See also
setFormat(), WDateTime::fromString()

◆ setInvalidNotADateTimeText()

void Wt::WDateTimeValidator::setInvalidNotADateTimeText ( const WString & text)

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

The default message is "The date and time must match the format {1}", with the format string as the first argument.

◆ setInvalidTooEarlyText()

void Wt::WDateTimeValidator::setInvalidTooEarlyText ( const WString & text)

Sets the message to display when the datetime is earlier than bottom().

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

◆ setInvalidTooLateText()

void Wt::WDateTimeValidator::setInvalidTooLateText ( const WString & text)

Sets the message to display when the datetime is later than top().

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

◆ setTop()

void Wt::WDateTimeValidator::setTop ( const WDateTime & top)

Sets the top of the valid datetime range.

The default is an empty datetime constructed using WDateTime::WDateTime().

◆ validate()

WValidator::Result Wt::WDateTimeValidator::validate ( const WString & input) const
overridevirtual

Validates the given input.

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

Reimplemented from Wt::WValidator.