adopted-ember-addons / adopted-ember-addons/ember-changeset-validations

Strange behavior with an array of objects

Đang mở
#345 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
215
Fork
98
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## VERSION
4.1.0

## Test Case
[Repo](https://github.com/AmauryD/ember-changeset-validations-bug-repro)
[The files](https://github.com/AmauryD/ember-changeset-validations-bug-repro/tree/main/app/components)

## Steps to reproduce

[In the test case]
1. Input some text in the comments
2. add some comments and some text
3. try to rollback

[In any changeset]
1. Have some array with objects inside of your changeset
2. Change the content of some objects in the array
3. Try to rollback/trigger validation

## Expected Behavior
The content of the object in the array also rollbacks.
Validation triggers properly for in-array object keys.

## Actual Behavior
The content of the objects in the array is not roll-backed after modification.
Impossible to make validation works for properties of nested objects. (except when a new object is added/deleted to the main array, but its not real-time for the properties of these objects)

Maybe i'm doing it the wrong way, i never saw support for this kind of structure and validation in ember-changeset, so let me know if it's a bug or just me !

Quick overview of the test case:
```js
const validator = {
title: [validatePresence(true)],
content: [validatePresence(true)],
comments: [
(e) => {
/**
* Validates only when array is changed
*/
console.log(e);
return true;
},
],
// not working
'comments.0.content': [
(e) => {
console.log(e);
return true;
},
],
};
...
Changeset({
title: 'Article',
comments: [
{
content: 'That was fun', <-- content does not validate when modified and does not rollback
},
{
content: 'That was not fun',
},
],
lookupValidator(validator),
validator
})
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.