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

isDirty is always true when initiating a Separated Properties with an array that has initial NULL value #531

Closed
r1y4h opened this issue Dec 2, 2019 · 6 comments

Comments

@r1y4h
Copy link

r1y4h commented Dec 2, 2019

Hi,

I am using Separated Properties with array of nested properties. I the array has initial value, the isDirty is set to true, but if the array has no initial values the isDirty is correctly set to false.

Here is a repl.it example:
Mobx-React-Form Seperated Properties Array isDirty

I am already using v2.0.8

@r1y4h r1y4h changed the title isDirty is always true when initiating a Separated Properties with nested array with value isDirty is always true when initiating a Separated Properties with an array that has initial value Dec 2, 2019
@r1y4h
Copy link
Author

r1y4h commented Dec 5, 2019

I temporarily hook into individual fields onChange event for the meantime.

@riceyeh
Copy link
Contributor

riceyeh commented Dec 8, 2019

This problem has nothing to do with array. I simplify your example as shown below. It is not an array, but it still fails. The current isDirty implementation does not work for fields (including form) having nested fields. But it should work for fields without nested fields after some bugs fixed by some pull requests from me. I privately implement isDirty-like method for fields with nested fields. Some assumptions are made in my implementation, so I do not bring it to mobx-react-form. For example, is a field dirty when some nested fields are added to it?

describe('isDrity with inital null values', () => {
   it('', () => {
    const fields = [
      'action',
      'action.applyBy',
      'action.amount',
    ]
    const labels = {
      'action.applyBy': 'Apply By',
      'action.amount': 'Discount Amount',
    }
    const types = {
      'action.amount': 'number',
    }
    const values = {
      action: {
        applyBy: null,
        amount: null,
      }
    } 

    const $531 = new Form({fields, labels, types, values}, {name: 'Form 531', options:{fallback: false}})
    expect($531.$('action.applyBy').isDirty).to.be.false
    expect($531.$('action.amount').isDirty).to.be.false
    expect($531.$('action').isDirty).to.be.false // fails
    expect($531.isDirty).to.be.false // fails
  })
});

@r1y4h
Copy link
Author

r1y4h commented Dec 9, 2019

hi @riceyeh

Thank you. In unified, IsDirty works fine but I guess there's no nested field yet.
When adding a new field I think IsDirty should remain false when there's no user change before and after the creation of new field.

@r1y4h
Copy link
Author

r1y4h commented Dec 9, 2019

I need IsDirty to work for nested fields. For now, I hook to every field's onChange event as a workaround

@foxhound87
Copy link
Owner

created a test, this is happening only when defining null values

foxhound87 added a commit that referenced this issue Mar 18, 2023
foxhound87 added a commit that referenced this issue Mar 18, 2023
@foxhound87 foxhound87 added the fix label Mar 18, 2023
@foxhound87 foxhound87 changed the title isDirty is always true when initiating a Separated Properties with an array that has initial value isDirty is always true when initiating a Separated Properties with an array that has initial NULL value Mar 18, 2023
foxhound87 added a commit that referenced this issue Mar 26, 2023
fix: #585 #531

fix: #585, fix #531
@github-actions
Copy link

🎉 This issue has been resolved in version 5.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

3 participants