6 #include "validatorrequiredifstash_p.h"
14 :
ValidatorRule(*new ValidatorRequiredIfStashPrivate(field, stashKey, stashValues, messages))
27 if (d->stashKey.isEmpty() || d->stashValues.isNull() || !d->stashValues.isValid()) {
29 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid validation data";
35 bool isRequired =
false;
39 const QVariant _stashValues = c->
stash(d->stashValues.toString());
49 const auto varList = _stashValues.
toList();
50 isRequired = varList.contains(sv);
54 qCWarning(C_VALIDATOR).noquote().nospace()
55 <<
debugString(c) <<
"Invalid validation data. The stash key \""
56 << d->stashValues.toString()
57 <<
"\" does not contain a QStringList or a QVariantList.";
64 const auto strList = d->stashValues.toStringList();
69 const auto varList = d->stashValues.toList();
70 isRequired = varList.contains(sv);
75 <<
"Invalid validation data. "
76 "stashValues has to be one of QString, "
77 "QStringList or QVariantList.";
81 if (isRequired && v.
isEmpty()) {
83 qCDebug(C_VALIDATOR).noquote().nospace()
84 <<
debugString(c) <<
" The field is not present or empty but stash key \""
85 << d->stashKey <<
"\" contains " << sv;
103 return c->
qtTrId(
"cutelyst-validator-genvalerr-req");
105 return c->
qtTrId(
"cutelyst-validator-genvalerr-req-label").
arg(_label);
void stash(const QVariantHash &unite)
QString qtTrId(const char *id, int n=-1) const
The field under validation must be present and not empty if the content of a stash key is equal to on...
~ValidatorRequiredIfStash() override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
ValidatorRequiredIfStash(const QString &field, const QString &stashKey, const QVariant &stashValues, const ValidatorMessages &messages=ValidatorMessages())
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
QString value(const ParamsMultiMap ¶ms) const
QString debugString(Context *c) const
The Cutelyst namespace holds all public Cutelyst API.
QString arg(Args &&... args) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
void setValue(QVariant &&value)
QList< QVariant > toList() const const
QString toString() const const
QStringList toStringList() const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.