6#include "validatoraccepted_p.h"
14 :
ValidatorRule(*new ValidatorAcceptedPrivate(field, messages))
28 result.
value.setValue<
bool>(
true);
31 result.
value.setValue<
bool>(
false);
33 "ValidatorAccepted: Validation failed for field %s at %s::%s.",
35 qPrintable(c->controllerName()),
36 qPrintable(c->actionName()));
45 static const QStringList l(
46 {QStringLiteral(
"yes"), QStringLiteral(
"on"), QStringLiteral(
"1"), QStringLiteral(
"true")});
47 ret = l.contains(
value, Qt::CaseInsensitive);
52 const QVariant &errorData)
const
56 const QString _label =
label(c);
57 if (_label.isEmpty()) {
58 error = c->
translate(
"Cutelyst::ValidatorAccepted",
"Has to be accepted.");
61 error = c->
translate(
"Cutelyst::ValidatorAccepted",
"“%1” has to be accepted.");
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
ValidatorAccepted(const QString &field, const ValidatorMessages &messages=ValidatorMessages())
Constructs a new accepted validator.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Creates a generic error message.
~ValidatorAccepted() override
Deconstructs the accepted validator.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString field() const
Returns the name of the field to validate.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
static bool validate(const QString &value)
Returns true if the value is yes, on, 1, or true.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.