-
Notifications
You must be signed in to change notification settings - Fork 649
[Issue 769]: Fix retrieval of the correct Object during $destroy on elements within an Array #770
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
Conversation
…lements within an Array
@doomie999 thanks for the PR, does this still work if there is an array within an array? |
@Anthropic Unfortunately, this fix doesn't work correctly on Arrays nested within Arrays. I used Having said that, I was actually able to access the ArrayIndex of the parent Array by using Would you be able to offer any advice on how to access the ArrayIndex of the parent Array? |
@doomie999 take a look at #742 it adds arrayIndeces which would give you the sub array path. I just merged it into the webpack-babel branch, if you re-target that branch it will be available to you. The changes may not be super clear on how to test it though, I am working on that at the moment and this weekend. |
@Anthropic I took a look at #742 and the webpack-babel branch (took a while because the change in build script from gulp to npm threw me off for a bit!) Pardon my inexperience, but I'm not quite sure how to go about using the fix for #742 in this issue. #742 creates the I could repeat the same logic written in #742 inside |
@joelwkent any ideas on the best way to get your arrayIndices into sfField for a destroy? |
Hi guys, apologies I had not seen this question until @Anthropic gave me a nudge on Gitter. I wonder if we can move the arrayIndices code to a service that could be used by this PR and conditions, onChange etc... I'm not 100% sure how to do this but I'll have a look over the code and report back shortly. |
@doomie999 I have committed some changes towards a solution, still have more work to do, but I think I have a way to make the details available soon-ish. |
@Anthropic Looking forward to your sharing of the details! I was exploring making a change to the Sadly, I didn't quite manage to get it to work, though I would be interested if you have any thoughts on this approach? |
@doomie999 the code I added passes the index and array indices to the scope by adding a controller above the added items and then importing that data using require ?^^sfKeyController into sfField. I have added the behaviour to array and tabarray. |
@doomie999 FYI the latest version in the ASF webpack branch seems to work better now. |
As I mentioned in #769 I believe I have this working in alpha.4 at the latest, so I will close this. Turned out that I changed the ng-repeat to use $$hashKey which seems to have done the trick. Thank you so much for your help on this @doomie999 I really appreciate it, you saved me a lot of time trying out variations I would have tried myself, so thank you! |
Description
During a $destroy (e.g. when conditions evaluate to false),
form.key
is used to access the appropriate part of the Model in order to apply the DestroyStrategy.This does not work for Elements within an Array, because
form.key
looks like this:['array', '', 'property']
In other words, it does not have a reference to the ArrayIndex of the Element (within which contains the property to be destroyed).
My fix was to make a copy of the
form.key
(in order to avoid breaking anything else that depends on its original format), and then update it so that it looks like this:['array', '5', 'property']
Where
'5'
here is just an example of the ArrayIndex.This "updated"
form.key
is then used in thesfSelect
to correctly access the appropriate part of the Model to be destroyed.Fixes Related issues
Checklist
@json-schema-form/angular-schema-form-lead