Wt
3.7.1
|
A validator for date input. More...
#include <Wt/WDateValidator>
Public Member Functions | |
WDateValidator (WObject *parent=0) | |
Creates a date validator. More... | |
WDateValidator (const WDate &bottom, const WDate &top, WObject *parent=0) | |
Creates a date validator. More... | |
WDateValidator (const WString &format, WObject *parent=0) | |
Creates a date validator. More... | |
WDateValidator (const WString &format, const WDate &bottom, const WDate &top, WObject *parent=0) | |
Creates a date validator. More... | |
void | setBottom (const WDate &bottom) |
Sets the bottom of the valid date range. More... | |
const WDate & | bottom () const |
Returns the bottom date of the valid range. | |
void | setTop (const WDate &top) |
Sets the top of the valid date range. More... | |
const WDate & | top () const |
Returns the top date of the valid range. | |
void | setFormat (const WString &format) |
Sets the date format used to parse date strings. More... | |
virtual WString | format () const |
Returns the format string used to parse date strings. More... | |
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 Result | validate (const WString &input) const |
Validates the given input. More... | |
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. More... | |
WString | invalidNotADateText () const |
Returns the message displayed when the input is not a date. More... | |
void | setInvalidTooEarlyText (const WString &text) |
Sets the message to display when the date is earlier than bottom. More... | |
WString | invalidTooEarlyText () const |
Returns the message displayed when date is too early. More... | |
void | setInvalidTooLateText (const WString &text) |
Sets the message to display when the date is later than top. More... | |
WString | invalidTooLateText () const |
Returns the message displayed when the date is too late. More... | |
virtual std::string | javaScriptValidate () const |
Creates a Javascript object that validates the input. More... | |
Public Member Functions inherited from Wt::WValidator | |
WValidator (WObject *parent=0) | |
Creates a new validator. | |
WValidator (bool mandatory, WObject *parent=0) | |
Creates a new validator. More... | |
~WValidator () | |
Destructor. More... | |
void | setMandatory (bool how) |
Sets if input is mandatory. More... | |
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. More... | |
WString | invalidBlankText () const |
Returns the message displayed when a mandatory field is left blank. More... | |
virtual std::string | inputFilter () const |
Returns a regular expression that filters input. More... | |
Public Member Functions inherited from Wt::WObject | |
WObject (WObject *parent=0) | |
Create a WObject with a given parent object. More... | |
virtual | ~WObject () |
Destructor. More... | |
virtual const std::string | id () const |
Returns the (unique) identifier for this object. More... | |
virtual void | setObjectName (const std::string &name) |
Sets an object name. More... | |
virtual std::string | objectName () const |
Returns the object name. More... | |
void | resetLearnedSlots () |
Resets learned stateless slot implementations. More... | |
template<class T > | |
void | resetLearnedSlot (void(T::*method)()) |
Resets a learned stateless slot implementation. More... | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)()) |
Declares a slot to be stateless and learn client-side behaviour on first invocation. More... | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
Declares a slot to be stateless and learn client-side behaviour in advance. More... | |
void | isNotStateless () |
Marks the current function as not stateless. More... | |
template<class T > | |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
Provides a JavaScript implementation for a method. More... | |
void | addChild (WObject *child) |
Adds a child object. More... | |
virtual void | removeChild (WObject *child) |
Removes a child object. More... | |
const std::vector< WObject * > & | children () const |
Returns the children. | |
WObject * | parent () const |
Returns the parent object. | |
Additional Inherited Members | |
Public Types inherited from Wt::WValidator | |
enum | State { Invalid, InvalidEmpty, Valid } |
The state in which validated input can exist. More... | |
Public Types inherited from Wt::WObject | |
typedef void(WObject::* | Method) () |
Typedef for a WObject method without arguments. | |
Protected Member Functions inherited from Wt::WObject | |
virtual WStatelessSlot * | getStateless (Method method) |
On-demand stateless slot implementation. More... | |
Static Protected Member Functions inherited from Wt::WObject | |
static WObject * | sender () |
Returns the sender of the current slot call. More... | |
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:
The strings used in the WDateValidator can be translated by overriding the default values for the following localization keys:
Wt::WDateValidator::WDateValidator | ( | WObject * | parent = 0 | ) |
Creates a date validator.
The validator will accept dates using the current locale's format.
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 using the current locale's format.
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()
|
virtual |
Returns the format string used to parse date strings.
Reimplemented from Wt::WValidator.
WString Wt::WDateValidator::invalidNotADateText | ( | ) | const |
Returns the message displayed when the input is not a date.
WString Wt::WDateValidator::invalidTooEarlyText | ( | ) | const |
Returns the message displayed when date is too early.
WString Wt::WDateValidator::invalidTooLateText | ( | ) | const |
Returns the message displayed when the date is too late.
|
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:
message
that indicates the problem if not valid.Returns an empty string if the validator does not provide a client-side validation implementationq.
Reimplemented from Wt::WValidator.
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.
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 | ) |
void Wt::WDateValidator::setTop | ( | const WDate & | top | ) |
Sets the top of the valid date range.
The default is a null date constructed using WDate().
|
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.