19 #include "validatornotin_p.h" 24 ValidatorRule(*new ValidatorNotInPrivate(field, values, cs, messages, defValKey))
38 if (d->values.empty()) {
40 qCWarning(C_VALIDATOR,
"ValidatorNotIn: The list of comparison values for the field %s at %s::%s is empty.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()));
42 const QString v =
value(params);
44 if (d->values.contains(v, d->cs)) {
46 qCDebug(C_VALIDATOR,
"ValidatorNotIn: Validation failed for field %s at %s::%s: \"%s\" is part of the list of not allowed comparison values.", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), qPrintable(v));
48 result.
value.setValue<QString>(v);
62 const QString _label =
label(c);
63 if (_label.isEmpty()) {
64 error = c->
translate(
"Cutelyst::ValidatorNotIn",
"Value is not allowed.");
66 error = c->
translate(
"Cutelyst::ValidatorNotIn",
"The value in the “%1” field is not allowed.").arg(_label);
75 const QString _label =
label(c);
76 if (_label.isEmpty()) {
77 error = c->
translate(
"Cutelyst::ValidatorNotIn",
"The list of comparison values is empty.");
79 error = c->
translate(
"Cutelyst::ValidatorNotIn",
"The list of comparison values for the “%1” field is empty.").arg(_label);
QMap< QString, QString > ParamsMultiMap
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
Stores custom error messages and the input field label.
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
Returns a generic error messages if the list of comparison values is empty.
~ValidatorNotIn()
Deconstructs the validator.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString field() const
Returns the name of the field to validate.
Contains the result of a single input parameter validation.
ValidatorNotIn(const QString &field, const QStringList &values, Qt::CaseSensitivity cs=Qt::CaseSensitive, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new not in validator.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
Checks if the field value is not one from a list of values.