Skip to content
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

Strange behavior with an array of objects #345

Open
AmauryD opened this issue Jun 14, 2022 · 2 comments
Open

Strange behavior with an array of objects #345

AmauryD opened this issue Jun 14, 2022 · 2 comments

Comments

@AmauryD
Copy link

AmauryD commented Jun 14, 2022

VERSION

4.1.0

Test Case

Repo
The files

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:

   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
   })
@jgadbois
Copy link

I am trying to do something similar - I have a property

results = [{ value: 1}]

Trying to validate 'results.0.value': validatePresence(true)

It's returning valid even if value is empty.

@jgadbois
Copy link

Note this appears to be related to the lookupValidator function, because if I use a standard validation object for the map, but use my own validation function, then it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants