.withName()
Returns a copy of the validator whose default messages start with name instead of value. It matters only when the validator validates a value directly; inside a schema, the field key is the field name and withName is ignored.
Signature
Section titled “Signature”Self withName(String? name)Parameters
Section titled “Parameters”| Parameter | Type | Meaning |
|---|---|---|
name |
String? |
The field name, or null to clear it. |
Code none. Default message: withName adds no validation. It changes the fieldName of every issue the validator produces, and so the value prefix of default messages.
Code generation
Section titled “Code generation”Every generated schema ends in .withName('ModelName'), which names the whole model in the must be a map message when $ModelValidate receives something that is not a map.
Example
Section titled “Example”final email = l.string().email().withName('email');final SchemaValidator $UserSchema = l.schema({...}).withName("User");l.string().email().withName('email').validate(input)+0-1- invalid:
'bad'
Inside a schema the key wins:
{contact: [contact must be a valid email address]}