adopted-ember-addons / ember-cp-validations

Ember computed property based validations
https://adopted-ember-addons.github.io/ember-cp-validations/
BSD 3-Clause "New" or "Revised" License
442 stars 174 forks source link

Validations with EmberObject does not work? #728

Closed ollar closed 1 year ago

ollar commented 2 years ago

Environment

Steps to Reproduce

I am trying to test the addon on a simple case:

import EmberObject from '@ember/object';
import { validator, buildValidations } from 'ember-cp-validations';

export const Validations = buildValidations({
  name: validator('presence', true),
  secondName: validator('presence', true),
  password: validator('presence', true),
});

export default class FormValidation extends EmberObject.extend(Validations) {
  name = '';
  secondName = '';
  password = '';
}

when I am using v-get in template:

{{v-get this.formModel 'name' 'message'}}

I get error

Uncaught Error: [ember-cp-validations] `lookupValidator` requires owner/container access.

Thanks!

kiwi-josh commented 2 years ago

How are you initializing your FormValidation class?

You may need to inject the owner if you are manually creating creating an instance (documentation).

Something like:

import { getOwner } from '@ember/application';

... 

FormValidation.create(
  getOwner(this).ownerInjection(),
  {
    ... // initial values
  }
)
acorncom commented 1 year ago

@ollar believe this can be closed now? The feedback from @kiwi-josh is accurate I believe

ollar commented 1 year ago

Thanks guys, seems that solves my question