ember-cp-validations icon indicating copy to clipboard operation
ember-cp-validations copied to clipboard

error.parentAttribute is not a string

Open basz opened this issue 8 years ago • 6 comments

Declared as string here https://github.com/offirgolan/ember-cp-validations/blob/master/addon/validations/error.js#L33

{{#each formModel.validations.errors as |error|}}
    <li>{{error.parentAttribute}} - {{error.attribute}} - {{error.message}}</li>
  {{/each}}

Model:<(unknown mixin):ember1701> - emailAddress - Deze waarde moet een geldig e-mail adres bevatten
Model:<(unknown mixin):ember1701> - addressDelivery.street - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressDelivery.populatedPlace - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressDelivery.postalCode - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressDelivery.country - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressVisiting.street - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressVisiting.populatedPlace - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressVisiting.postalCode - Deze waarde mag niet leeg zijn
Model:<(unknown mixin):ember1701> - addressVisiting.country - Deze waarde mag niet leeg zijn

In this instance I'm trying to validate an emailAddress is a polymorphic model (fragment) of a primaryContact property on the base model. Its property 'path' is more like 'primaryContact.[index].emailAddress. I'm juggling forms inside form, so it might be the path 'emailAddress' error comes from there. I was hoping to use the parentAttribute for some checks.

basz avatar Jan 28 '18 12:01 basz

@basz I believe parentAttribute is only set for nested validations. Usually when used via a belongsTo or hasMany.

offirgolan avatar Jan 29 '18 17:01 offirgolan

That would seem logical. Yet it is not a string...

basz avatar Jan 29 '18 17:01 basz

Oh.... what is it then?

offirgolan avatar Jan 29 '18 18:01 offirgolan

Dunno, an unknown mixin? See above? Probably the parent model. But not a string as the api docs say. Attribute on the other hand is. So in combinating both one should be able to create a full path...

basz avatar Jan 29 '18 19:01 basz

Any chance you can make a twiddle to reproduce this?

offirgolan avatar Feb 16 '18 19:02 offirgolan

I'm facing a similar issue, parentAttribute is a string but is like "Model:<(unknown):ember333>"

Very simple reproduction here: https://ember-twiddle.com/a863a3cbd1e43164669f3aebb5cfdad9?openFiles=templates.application.hbs%2C

Maybe I'm doing something wrong? Is the intention for parentAttribute to equal "post" in the above twiddle's case?

edit: Looks like parentAttribute is set here and the ResultCollections attribute is set here via

attribute: `Model:${this}`

Would setting this to the parents model name make more sense for nested validations?

Subtletree avatar Aug 10 '18 00:08 Subtletree