New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation support for subproperties #283

Open
ericIMT opened this Issue Aug 25, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@ericIMT

ericIMT commented Aug 25, 2016

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.

@ericIMT ericIMT changed the title from Validation support for sub properties to Validation support for subproperties Aug 25, 2016

@doktordirk

This comment has been minimized.

Show comment
Hide comment
@doktordirk

doktordirk Sep 5, 2016

Contributor

that'll be useful to have

Contributor

doktordirk commented Sep 5, 2016

that'll be useful to have

ericIMT added a commit to ericIMT/validation that referenced this issue Sep 19, 2016

ericIMT added a commit to ericIMT/validation that referenced this issue Sep 20, 2016

@jdanyow

This comment has been minimized.

Show comment
Hide comment
@jdanyow

jdanyow Sep 26, 2016

Member

todo: consider #332 when implementing this.

Member

jdanyow commented Sep 26, 2016

todo: consider #332 when implementing this.

ericIMT added a commit to ericIMT/validation that referenced this issue Oct 3, 2016

ericIMT added a commit to ericIMT/validation that referenced this issue Oct 7, 2016

@swalters

This comment has been minimized.

Show comment
Hide comment
@swalters

swalters Oct 15, 2016

Wouldn't it be more appropriate to create separate validation rules for Address and then allow a .valid on those rules? This is how NHibernate Validator works. I wouldn't want to define rules for a reusable class everywhere it is associated with another class.

I really need this in my application.

NHibernate Validator examples

//to validate a one-to-one association
Define(x => x.PropertyReferencingClass)
        .IsValid();


//to validate a one-to-many association
Define(x => x.SomePropertyCollection)
        .HasValidElements();

swalters commented Oct 15, 2016

Wouldn't it be more appropriate to create separate validation rules for Address and then allow a .valid on those rules? This is how NHibernate Validator works. I wouldn't want to define rules for a reusable class everywhere it is associated with another class.

I really need this in my application.

NHibernate Validator examples

//to validate a one-to-one association
Define(x => x.PropertyReferencingClass)
        .IsValid();


//to validate a one-to-many association
Define(x => x.SomePropertyCollection)
        .HasValidElements();

ericIMT added a commit to ericIMT/validation that referenced this issue Oct 18, 2016

ericIMT added a commit to ericIMT/validation that referenced this issue Oct 18, 2016

ericIMT added a commit to ericIMT/validation that referenced this issue Oct 31, 2016

@DavidBLynch

This comment has been minimized.

Show comment
Hide comment
@DavidBLynch

DavidBLynch Nov 15, 2016

Curious why this is on-hold? It seems like if binding supports binding paths then validation should as well!

DavidBLynch commented Nov 15, 2016

Curious why this is on-hold? It seems like if binding supports binding paths then validation should as well!

ericIMT added a commit to ericIMT/validation that referenced this issue Dec 19, 2016

ericIMT added a commit to ericIMT/validation that referenced this issue Dec 19, 2016

@phinett

This comment has been minimized.

Show comment
Hide comment
@phinett

phinett Feb 23, 2017

Is there an update on the status of this, is this still not supported?
Thanks.

phinett commented Feb 23, 2017

Is there an update on the status of this, is this still not supported?
Thanks.

@jdanyow

This comment has been minimized.

Show comment
Hide comment
@jdanyow

jdanyow May 20, 2017

Member

Also related: #442

Member

jdanyow commented May 20, 2017

Also related: #442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment