|
cutelyst 3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Provides information about performed validations. More...
#include <Cutelyst/Plugins/Utils/ValdatorResult>
Public Member Functions | |
| ValidatorResult () | |
| Constructs a new ValidatorResult. | |
| ValidatorResult (const ValidatorResult &other) | |
| Constructs a copy of other. | |
| ~ValidatorResult () | |
| Deconstructs the ValidatorResult. | |
| void | addError (const QString &field, const QString &message) |
| Adds new error information to the internal QHash. | |
| void | addExtra (const QString &field, const QVariant &extra) |
| Adds new extra data that came up when validating the input field. | |
| void | addValue (const QString &field, const QVariant &value) |
| Adds a new value extracted from the specified input field. | |
| QHash< QString, QStringList > | errors () const |
| Returns a dictionary containing fields with errors. | |
| QStringList | errors (const QString &field) const |
| Returns a list of all error messages for an input field. | |
| QJsonObject | errorsJsonObject () const |
| Returns the dictionray containing fields with errors as JSON object. | |
| QStringList | errorStrings () const |
| Returns a list of all error messages. | |
| QVariant | extra (const QString &field) const |
| Returns the extra data for the input field. | |
| QVariantHash | extras () const |
| Returns all extra data that has been extracted by the validators. | |
| QStringList | failedFields () const |
| Returns a list of fields with errors. | |
| bool | hasErrors (const QString &field) const |
Returns true if the field has validation errors. | |
| bool | isValid () const |
Returns true if the validation was successful. | |
| operator bool () const | |
Returns true if the validation was successful. | |
| ValidatorResult & | operator= (const ValidatorResult &other) |
| Assigns other to this ValidatorResult. | |
| QVariant | value (const QString &field) const |
| Returns the extracted value for the input field. | |
| QVariantHash | values () const |
| Returns the values that have been extracted by the validators. | |
ValidatorResult will be returned by Validator when calling validate() on it. It contains information about occurred validation errors, like the error strings of each failed validator and a list of fields where validation failed.
Additionally to the error messages that occure if validation fails for one or more fields, ValidatorResult will also contain the extracted values from the input parameters. Use values() to return all values or value() to return the value for a single field. Because there will be only one value stored for each field, you should order your validators in a way that a validator for a field comes last that converts the input QString into the wanted type. See the documentation for the specific validator to see what type of data it returns.
Some validators might even return more details about the validation result. This extra data can be returned with the extras() method for all input parameters or with extra() for a single one.
Beside the isValid() function, that returns true if the complete validation process was successful and false if any of the validators failed, ValidatorResult provides a bool operator that makes it usable in if statements.
Validity is simply determined by the fact, that it does not contain any error information.
Definition at line 71 of file validatorresult.h.
| ValidatorResult::ValidatorResult | ( | ) |
A newly constructed ValidatorResult willl be valid by default, because it does not contain any error information.
Definition at line 13 of file validatorresult.cpp.
Referenced by ValidatorResult(), and operator=().
| ValidatorResult::ValidatorResult | ( | const ValidatorResult & | other | ) |
Definition at line 18 of file validatorresult.cpp.
References ValidatorResult().
| ValidatorResult::~ValidatorResult | ( | ) |
Definition at line 29 of file validatorresult.cpp.
| field | Name of the input parameter that has validation errors. |
| message | Error message shown to the user. |
Definition at line 38 of file validatorresult.cpp.
References QList::append(), and QList::value().
Referenced by Cutelyst::Validator::validate().
| field | Name of the input parameter the extra data occurred for. |
| extra | The additional validation data. |
Definition at line 118 of file validatorresult.cpp.
References extra().
Referenced by Cutelyst::Validator::validate().
| field | Name of the input parameter the value has been extracted from. |
| value | Value as it has been extracted and maybe converted by the validator. |
Definition at line 103 of file validatorresult.cpp.
References value().
Referenced by Cutelyst::Validator::validate().
| QHash< QString, QStringList > ValidatorResult::errors | ( | ) | const |
Definition at line 58 of file validatorresult.cpp.
Referenced by Cutelyst::Validator::validate().
| QStringList ValidatorResult::errors | ( | const QString & | field | ) | const |
| field | Name of the field to return error messages for. |
Definition at line 63 of file validatorresult.cpp.
References QList::value().
| QJsonObject ValidatorResult::errorsJsonObject | ( | ) | const |
This returns the same data as errors() but converted into a JSON object that has the field names as keys and the values will be a JSON array of strings containing the errors for the field.
Definition at line 73 of file validatorresult.cpp.
References QJsonArray::fromStringList(), and QJsonObject::insert().
| QStringList ValidatorResult::errorStrings | ( | ) | const |
Definition at line 45 of file validatorresult.cpp.
References QList::append(), and QList::constBegin().
Referenced by Cutelyst::Validator::validate().
| field | Name of the input parameter to get the extra data for. |
Definition at line 113 of file validatorresult.cpp.
References QVariant::value().
Referenced by addExtra().
| QVariantHash ValidatorResult::extras | ( | ) | const |
Definition at line 108 of file validatorresult.cpp.
| QStringList ValidatorResult::failedFields | ( | ) | const |
Definition at line 88 of file validatorresult.cpp.
| bool ValidatorResult::hasErrors | ( | const QString & | field | ) | const |
| field | Name of the input field to check. |
true if the field has error messages, false otherwise. Definition at line 68 of file validatorresult.cpp.
| bool ValidatorResult::isValid | ( | ) | const |
Definition at line 33 of file validatorresult.cpp.
Referenced by operator bool().
|
inlineexplicit |
Definition at line 168 of file validatorresult.h.
References isValid().
| ValidatorResult & ValidatorResult::operator= | ( | const ValidatorResult & | other | ) |
Definition at line 23 of file validatorresult.cpp.
References ValidatorResult().
| field | Name of the input parameter to get the value for. |
Definition at line 98 of file validatorresult.cpp.
References QVariant::value().
Referenced by addValue().
| QVariantHash ValidatorResult::values | ( | ) | const |
Definition at line 93 of file validatorresult.cpp.