19 #include "validatorcharnotallowed_p.h"
24 ValidatorRule(*new ValidatorCharNotAllowedPrivate(field, forbiddenChars, messages, defValKey))
38 for (
const QChar &forbiddenChar : forbiddenChars) {
39 if (
value.contains(forbiddenChar)) {
42 *foundChar = forbiddenChar;
57 const QString v =
value(params);
59 if (Q_LIKELY(!d->forbiddenChars.isEmpty())) {
62 result.
value.setValue<QString>(v);
67 qCWarning(C_VALIDATOR) <<
"ValidatorCharNotAllowed: Empty validation data for field" <<
field() <<
"at" << c->controllerName() <<
"::" << c->actionName();
80 const QChar foundChar = errorData.toChar();
82 const QString _label =
label(c);
83 if (_label.isEmpty()) {
84 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"Must not contain the following characters: “%1”. But contains the following illegal character: “%2”.").arg(d->forbiddenChars, QString(foundChar));
86 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"The text in the “%1“ field must not contain the following characters: “%2“. But contains the following illegal character: “%3”.").arg(_label, d->forbiddenChars, QString(foundChar));
96 const QString _label =
label(c);
97 if (_label.isEmpty()) {
98 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"The list of illegal characters for this field is empty.");
100 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"The list of illegal characters for the “%1“ field is empty.").arg(_label);
QMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
~ValidatorCharNotAllowed() override
Deconstructs the char not allowed validator.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if the list of forbidden characters is empty.
ValidatorCharNotAllowed(const QString &field, const QString &forbiddenChars, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new char not allowed validator.
Base class for all validator rules.
Validates an input field for not allowed characters.
static bool validate(const QString &value, const QString &forbiddenChars, QChar *foundChar=nullptr)
Returns true if value does not contain any of the charachters in forbiddenChars.
QString field() const
Returns the name of the field to validate.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
Contains the result of a single input parameter validation.
The Cutelyst namespace holds all public Cutelyst API.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
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 ...