cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatoraccepted.cpp
1/*
2 * SPDX-FileCopyrightText: (C) 2017-2023 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "validatoraccepted_p.h"
7
8#include <QStringList>
9
10using namespace Cutelyst;
11
12const QStringList ValidatorAcceptedPrivate::trueVals{u"yes"_qs, u"on"_qs, u"1"_qs, u"true"_qs};
13
15 const Cutelyst::ValidatorMessages &messages)
16 : ValidatorRule(*new ValidatorAcceptedPrivate(field, messages))
17{
18}
19
21
23 const Cutelyst::ParamsMultiMap &params) const
24{
26
27 if (Q_LIKELY(ValidatorAccepted::validate(value(params)))) {
28 result.value.setValue<bool>(true);
29 } else {
30 result.errorMessage = validationError(c);
31 result.value.setValue<bool>(false);
32 qCDebug(C_VALIDATOR).noquote() << debugString(c);
33 }
34
35 return result;
36}
37
39{
40 return ValidatorAcceptedPrivate::trueVals.contains(value, Qt::CaseInsensitive);
41}
42
44 const QVariant &errorData) const
45{
46 Q_UNUSED(errorData)
47 const QString _label = label(c);
48 if (_label.isEmpty()) {
49 //% "Has to be accepted."
50 return c->qtTrId("cutelyst-valaccepted-genvalerr");
51 } else {
52 //: %1 will be replaced by the field label
53 //% "“%1” has to be accepted."
54 return c->qtTrId("cutelyst-valaccepted-genvalerr-label").arg(_label);
55 }
56}
The Cutelyst Context.
Definition context.h:42
QString qtTrId(const char *id, int n=-1) const
Definition context.h:656
ValidatorAccepted(const QString &field, const ValidatorMessages &messages=ValidatorMessages())
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
QString value(const ParamsMultiMap &params) const
QString debugString(Context *c) const
static bool validate(const QString &value)
Returns true if the value is equal to yes, on, 1, or true.
The Cutelyst namespace holds all public Cutelyst API.
QString arg(Args &&... args) const const
bool isEmpty() const const
CaseInsensitive
void setValue(QVariant &&value)
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.