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

Presence validation on belongsTo relationship stopped working on 3.11.

Open alejandrodevs opened this issue 6 years ago • 6 comments
trafficstars

Environment

  • Ember Version: 3.11.1
  • Ember CLI Version: 3.11.0
  • Ember CP Validations Version: 4.0.0-beta.9

Steps to Reproduce

After I upgraded from ember 3.10 to 3.11 the presence validations on belongsTo relationships stopped working. Looks like it does not detect that the associated record has changed and displays This field can't be blank even when record is well assigned.

After I ran notifyPropertyChange on that property the validations get updated and works correctly.

This is how my model looks like:

import attr from 'ember-data/attr';
import Model from 'ember-data/model';
import { belongsTo } from 'ember-data/relationships';
import { buildValidations, validator } from 'ember-cp-validations';

const Validations = buildValidations({
  title: [
    validator('presence', true)
  ],
  author: [
    validator('presence', true)
  ]
});

export default Model.extend(Validations, {
  title:  attr('string'),

  author: belongsTo()
});

alejandrodevs avatar Aug 08 '19 14:08 alejandrodevs

Adding debounce value makes it work:

export default buildValidations({
  title: [
    validator('presence', true)
  ],
  author: [
    validator('presence', {
      presence: true,
      debounce: 10
    })
  ]
});

This is working but it is not the best approach. Any thoughts?

alejandrodevs avatar Aug 08 '19 16:08 alejandrodevs

I can confirm that this is still an issue in Ember 3.12:

  • Ember Version: 3.12.0
  • Ember CLI Version: 3.12.0
  • Ember CP Validations Version: 4.0.0.beta-9

fran-worley avatar Aug 20 '19 05:08 fran-worley

I can confirm that this is an issue with Ember 3.12.x (both source and data) and I've also tried the latest beta 4.0.0.beta-10 - are there any plans to fix this issue in the near future? Thanks!

arm1n avatar Jan 30 '20 10:01 arm1n

This is working on Ember 3.16, CP validations version 4.0.0-beta.10

maxwondercorn avatar Aug 04 '20 04:08 maxwondercorn

@alejandrodevs @fran-worley @arm1n @erikap we droped support for ember versions < 3.16 in the last beta. Can someone confirm @maxwondercorn statement, that it work in ember versions >= 3.16?

fsmanuel avatar Sep 11 '22 10:09 fsmanuel

I think it was fixed here https://github.com/adopted-ember-addons/ember-cp-validations/commit/369f080f089fc3d9ad452dd8bfd7ae2330e94ce6

fsmanuel avatar Sep 11 '22 10:09 fsmanuel