6 #include "validatorrequiredunlessstash_p.h"
15 *new ValidatorRequiredUnlessStashPrivate(field, stashKey, stashValues, messages))
28 if (d->stashKey.isEmpty() || d->stashValues.isNull() || !d->stashValues.isValid()) {
30 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid validation data";
36 bool isRequired =
false;
40 const QVariant _stashValues = c->
stash(d->stashValues.toString());
50 const auto varLst = _stashValues.
toList();
51 isRequired = !varLst.contains(sv);
55 qCWarning(C_VALIDATOR).noquote().nospace()
56 <<
debugString(c) <<
"Invalid validation data. The stash key \""
57 << d->stashValues.toString()
58 <<
"\" does not contain a QStringList or a QVariantList.";
65 const auto strLst = d->stashValues.toStringList();
70 const auto varList = d->stashValues.toList();
71 isRequired = !varList.contains(sv);
76 <<
"Invalid validation data. "
77 "stashValues has to be one of QString, "
78 "QStringList or QVariantList.";
82 if (isRequired && v.
isEmpty()) {
84 qCDebug(C_VALIDATOR).noquote().nospace()
85 <<
debugString(c) <<
" The field is not present or empty but stash key \""
86 << d->stashKey <<
"\" does not contain " << sv;
104 return c->
qtTrId(
"cutelyst-validator-genvalerr-req");
106 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 unless the content of a stash key is equal t...
ValidatorRequiredUnlessStash(const QString &field, const QString &stashKey, const QVariant &stashValues, const ValidatorMessages &messages=ValidatorMessages())
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
~ValidatorRequiredUnlessStash() override
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.