aurelia / aurelia/validation

Validation support for subproperties

Open
#283 6 comments 11 reactions 0 assignees View on GitHub
enhancement on-hold
Dominant language
TypeScript
Stars
129
Forks
125
PR merge metrics
No merged PRs in 30d

Description

**I'm submitting a feature request**

**Current behavior:**

Given the follwing template code:
<input type="hidden" value.bind="newEntry.address.street1 &validate" />
<input type="hidden" value.bind="newEntry.address.street2 &validate" />
<input type="hidden" value.bind="newEntry.address.city &validate" />

And the current validation code (using aurelia-validatejs)

this.validationRules = new ValidationRules()
.ensure("address.street1").required().length({minimum:5, maximum:50}).
.ensure("address.street2").length({minimum:5, maximum:50}).
.ensure("address.city").length({minimum:5, maximum:50}).
...
on(this.newEntry);

The validation controller passes to the validator for (street1, street2 and city)
the propertyName : street1,street2 or city (depending on the field being validated)
and the following object:
{
street1:"",
street2:"".
city:"",
}

**Expected/desired behavior:**

Expected behaviour would to pass the entire object being validated not just the object containing the sub-property,
e.g
{
address: {
street1:"",
street2:"".
city:"",
}
}
Also, the full "path" to the property from the object "root" e.g. address.street1 instead of "street1"

**What is the motivation / use case for changing the behaviour?**

The motivation for this change is due to how aurelia-validationjs stores the rules as metadata in the containing object (newEntry in this case).
It is unable to find any rules when the address object is passed to it.

Also we will need the full path of the property (e.g address.street1) as the rules for sub-properties are defined as, for example, "address.street1" not "street1". It needs the path to be able to find the correct rule.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the validation controller behavior described in the issue and how aurelia-validatejs looks up rules for nested properties. Verify how the current property name and containing object are passed for address.street1, address.street2, and address.city. Done means the validator receives the root object and the full property paths so the declared subproperty rules can be found.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.