Cutelyst  1.5.0
Public Member Functions | Protected Member Functions | List of all members
Cutelyst::ValidatorRequiredUnless Class Reference

The field under validation must be present and not empty unless the other field is equal to any value in the list. More...

#include <validatorrequiredunless.h>

Inheritance diagram for Cutelyst::ValidatorRequiredUnless:
Inheritance graph
[legend]

Public Member Functions

 ValidatorRequiredUnless (const QString &field, const QString &otherField, const QStringList &otherValues, const QString &label=QString(), const QString &customError=QString())
 Constructs a new required unless validator. More...
 
 ~ValidatorRequiredUnless ()
 Deconstructs the required unless validator.
 
void setOtherField (const QString &otherField)
 Sets the name of the other field.
 
void setOtherValues (const QStringList &otherValues)
 Sets the comparative values for the other field.
 
QString validate () const override
 Performs the validation and returns an empty QString on success, otherwise an error message.
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const QString &label=QString(), const QString &customError=QString())
 Constructs a new ValidatorRule with given parameters and parent. More...
 
 ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 
QString field () const
 Returns the name of the field to validate. More...
 
QString label () const
 Returns the human readable field label used for generic error messages. More...
 
ParamsMultiMap parameters () const
 Returns the parameters to validate. More...
 
void setCustomError (const QString &customError)
 Sets a cutom error returned with errorMessage() More...
 
void setCustomParsingError (const QString &custom)
 Sets a custom error message that is shown if parsing of input data fails. More...
 
void setCustomValidationDataError (const QString &custom)
 Sets a custom error message if validation data is invalid or missing. More...
 
void setField (const QString &field)
 Sets the name of the field to validate. More...
 
void setLabel (const QString &label)
 Sets human readable field label for generic error messages. More...
 
void setParameters (const ParamsMultiMap &params)
 Sets the request parameters to validate. More...
 
void setTrimBefore (bool trimBefore)
 Set to false to not trim input value before validation. More...
 
bool trimBefore () const
 Returns true if field value should be trimmed before validation. More...
 
QString value () const
 Returns the field value.
 

Protected Member Functions

 ValidatorRequiredUnless (ValidatorRequiredUnlessPrivate &dd)
 
QString genericValidationError () const override
 Returns a generic error message.
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 
virtual QString genericParsingError () const
 Returns a generic error message if an error occures while parsing input. More...
 
virtual QString genericValidationDataError () const
 Returns a generic error message if any validation data is missing or invalid. More...
 
QString parsingError () const
 Returns an error message if an error occured while parsing input. More...
 
QString validationDataError () const
 Returns an error message if any validation data is missing or invalid. More...
 
QString validationError () const
 Returns a descriptive error message if validation failed. More...
 

Additional Inherited Members

- Protected Attributes inherited from Cutelyst::ValidatorRule
const QScopedPointer< ValidatorRulePrivate > d_ptr
 

Detailed Description

If the other field specified as otherField does not conaint any of the values specified in the otherValues list, the field under validation must be present and not empty.

If ValidatorRule::trimBefore() is set to true (the default), whitespaces will be removed from the beginning and the end of the input value before validation. So, fields that only contain whitespaces will be treated as empty.

See Validator for general usage of validators.

See also
ValidatorRequired, ValidatorRequiredIf, ValidatorRequiredWith, ValidatorRequiredWithAll, ValidatorRequiredWithout, ValidatorRequiredWithoutAll

Definition at line 43 of file validatorrequiredunless.h.

Constructor & Destructor Documentation

Cutelyst::ValidatorRequiredUnless::ValidatorRequiredUnless ( const QString &  field,
const QString &  otherField,
const QStringList &  otherValues,
const QString &  label = QString(),
const QString &  customError = QString() 
)
Parameters
fieldName of the input field to validate.
otherFieldName of the other input field to validate.
otherValuesList of values that are not allowed to be in the other field to require the main field.
labelHuman readable input field label, used for generic error messages.
customErrorCustom error message if validation fails.