Skip to content

AutoForm.getFieldValue() returns undefined after removing any elements from #afEachArrayItem #833

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

Closed
miri-am opened this issue Mar 27, 2015 · 10 comments

Comments

@miri-am
Copy link

miri-am commented Mar 27, 2015

After I delete an element from a form (using #afEachArrayItem), the AutoForm.getFieldValue() is not working anymore. It seems that this.current index does not match the one getFieldValue() uses.

I set up repository showing the problem: https://github.com/miri-am/autoform-destroy-test

  1. Choose Type: "Text"; //Should show "Text"
  2. Add Element and choose Type: "Photo"; //Should show "Photo"
  3. Delete second element
  4. Add element and choose Type. // now undefined, see logs from currentActionType helper;

Am I doing something wrong or is this not supported by Autoform?

@BradRyan
Copy link

Perhaps unrelated, but my issue seemed similar. I'm getting AutoForm.getFieldValue() to return undefined after performing an update function. The form field still contains a value that I was using elsewhere with a getFieldValue(), but after submitting/updating the form, it returns undefined.

This getFieldValue in 5.1 is haunting me... 😭

If I put AutoForm.getFieldValue("fieldName"); in the developer console, it returns:
"Error: There is no current view"

@agusputra
Copy link

Hi @BradRyan I think I also experienced this. #843

@miri-am
Copy link
Author

miri-am commented Apr 16, 2015

@aldeed. Any hint on my issue? Am I doing something wrong there or is this a bug? Appreciate any hint that helps me to resolve the issue. Thanks

@vishim
Copy link

vishim commented Apr 26, 2015

I am facing the exact same issue. Have been stuck for long thinking I am doing something wrong.
Please help @aldeed

@aldeed
Copy link
Collaborator

aldeed commented Aug 3, 2015

The problem is that in AutoForm.getFieldValue, AutoForm.getFormValues returns a compacted array, so item 2 is moved to item 1, leaving item 2 undefined.

This gets into the complexity of the array tracker, so I'll have to figure out a proper solution.

@7ammer
Copy link

7ammer commented Feb 28, 2016

Its like this for me:

  • Choose Type: "Text"; //Should show "Text" this.current.type = layout.1.type
  • Add Element and choose Type: "Photo"; //Should show "Photo"
    this.current.type = layout.2.type
  • Delete second element // should delete: this.current.type = layout.2.type
  • Add element and choose Type. // Added element shows: this.current.type = layout.3.type?!

The added element should = layout.2.type and replace the previous array item but instead it just pushes to the array. No idea if layout.2.type still exists.

@chneau
Copy link

chneau commented Mar 21, 2016

Just to add what I found, I am doing a custom field for an array and I wanted to have sort of an "afFieldValueIsIn" helper. I found everytime you add an item to the array via AutoForm the index is like this: 1,2,3. Then, if you delete the second item via AutoForm remove item button, index are like this. 1, 3. getFieldValue of the now "second item" is getFieldValue('example.3.example') but doesn't exist.

I found that you still be able to know the value of the second item but for this you need to getFieldValue('example.2.example').

@myktra
Copy link

myktra commented May 6, 2016

This bug makes it difficult to use array fields in AutoForm for anything beyond basic use cases. If you want to provide any kind of custom options for a type="select" field that depend on other field values in the same array item, you're out of luck, since you can't rely on introspecting data from the current array item via AutoForm.getFieldValue().

@fashkl
Copy link

fashkl commented Nov 26, 2020

The problem is that in AutoForm.getFieldValue, AutoForm.getFormValues returns a compacted array, so item 2 is moved to item 1, leaving item 2 undefined.

This gets into the complexity of the array tracker, so I'll have to figure out a proper solution.

@aldeed Hi Eric, any update regarding this? any suggested solution?

@jankapunkt
Copy link
Member

@fashkl yesterday we released the new major 7.0 release. Would you mind giving it a try and see if this issue got resolved? These functions are also mentioned in the CHANGELOG (although this was implemented by @pouya-eghbali).

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

10 participants