-
Notifications
You must be signed in to change notification settings - Fork 6
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
Collapsible Nested Arrays #71
Comments
OK so, here's what I have so far: Header is one of these:
I start working on nested arrays now. Let me know if you have any ideas or you want any changes. (sorry for the horrible gif) |
Looking good already. I do not think we need a title inside the collapsible body... its title is in the collapsible header. Also, an edit icon on the right will inform the user than clicking is possible to edit, just like the drag icon indicates that it can be dragged. |
Perhaps also move delete per item also on the right (on left of edit). With delete, make sure to have a confirm dialogue to avoid accidental delete. |
For the header of the collapsible, it may need to support a callback function to allow custom styling and summarization. |
Yes, I will add that too. Currently, for the header we can define a custom template OR a field name, we must add function support too because it's so much easier than custom templates. |
Scrap that - a custom template will be better, dynamically rendered inside the collection item header. |
I managed to fix the nested draggable hell by adding a unique class to each item's handle and also their container. Now I just need to fix field names, I have some plans to simplify this part, I hope that works. I'll start this after lunch time! |
Ok for some reason Template.afArrayField_materialize.onRendered(() => {
const instance = Template.instance()
const template = this;
... Any idea why it doesn't work? There's also an issue with |
There's also an issue with blaze, it updates the wrong header text when it is changed. Trying to figure out why? Possibly because moving items doesn't change the DOM tree. |
OR, maybe ^ is because autoform. Investigating. |
Even doing a flex-box order doesn't fix the issue |
OK I see what's wrong |
I found some magical ways to fix the problem |
I'm reading autoform source. ArrayTracker.prototype.getField = function atGetField(formId, field) {
var self = this;
self.ensureField(formId, field);
self.info[formId][field].deps.depend();
return self.info[formId][field].array;
}; If we can change |
AutoForm.arrayTracker.info[formId][field].deps.changed() Causes a re-render of the array field. Need to figure out how to set field data now. |
OK. Here's the current situation:
to get the header value. Here's the fieldValue(current, formId, fieldName) {
if (!fieldName) {
// sort alphabetically and get first fieldName
fieldName = Object.keys(current).sort((a, b) => a > b ? 1 : -1)[0]
}
return AutoForm.getFieldValue(current[fieldName], formId)
} in the above function, I managed to solve all problems, except this one, but i'm working on it |
I don't know if this is happening because blaze or because afEachArrayItem, this isn't an issue with draggable and dom/schema-key manipulation, it happens even if I don't drag. Simply adding and removing items causes the headers to be wrong. |
Looks like I found a way. If I do this:
it seems to work. let me write a function that does this automatically, hopefully it solves the issue. |
Doesn't work. What I've tried:
And a few other things I tried. Well, I don't know how to solve the header problem. Any ideas? |
Last idea I have for the header:
That's my last idea. None of the others worked. |
Yeah, |
Seems I missed all the action, bravo for finding a solution. I remember when I wrote the array drag stuff before it was quite challenging to get it to work with autoform. |
I've also remembered something about when array items are removed, it leaves undefined items the array in the DB instead of replacing the entire array. |
I generally find a lot of reactive solutions are possible using autorun and sub-templates. |
Yes, I saw your messages in autoform issues! I checked a lot of them today |
Ok it works perfectly, I'll do a little polishing and cleaning |
Another issue! After reordering nested arrays and submitting the form, I get a million errors and warnings in the console. Form submit works, values submit correctly, reordering of arrays works, but there's this error.
and
and finally
These get repeated a million times. The first two are coming from an instance.autorun, the |
Ok, after submitting the form, in dom I see the |
Here's the situation:
|
How many levels deep are you going? |
I will check it out in the playground later this week. |
3 levels
Pretty sure this is related: Meteor-Community-Packages/meteor-autoform#638 |
I started investigating this in autoform source, seems like it is caused by |
This isn't directly caused by arrayTracker, but caused by helpers that use the above methods:
|
in arrayTracker.initField(formId, name, ss, docCount, c.atts.minCount, c.atts.maxCount);
return arrayTracker.getField(formId, name); first one does a |
No effect, something is resetting ALL arrayTracker data. |
Tracing back to |
Tracing back to autoform again, |
Tracing back to |
Tracing back to autoform, the |
I'm going to stop working on this for a while, I'm a little tired of trying to solve it all day everyday. I need to clear my mind. Apparently |
Further investigation:
|
This is heavy stuff, I know. Thank you for your effort so far. Let me play with it until next week Wed. |
This may be the issue:
This means, each time we add an item it triggers a re-render for |
Ok this isn't related to For references: Meteor-Community-Packages/meteor-autoform#795 |
Some more clues:
|
Maybe I can solve this by providing a |
Some hints for a solution: http://blazejs.org/api/spacebars.html#Reactivity-Model-for-Each |
More clues: meteor/blaze#241 |
I solved the issue :) |
Sorry for the amount of comments I made, I was just logging what I'm doing so if in the future someone wants to work on this they have a clue where to start and what we already tried. Anyways, I forked autoform and I have my changes here: https://github.com/pouya-eghbali/meteor-autoform I'm not going to make a pull request, there are 22 open pull requests and 530 open issues on the original repo, this issue was posted there a few years ago and nobody cared to solve it, or nobody figured how to, well I guess I have to maintain my own copy of autoform. So, what was the issue? It's actually, simple. Autoform maintains a list (a JavaScript Array) of items for each array field, in its ArrayTracker. In Checking the source code of Problem is, this diffing function doesn't work well with arrays of objects, so when the Reading the Blaze documentation and issues, I figured the diffing function works really well with mongo queries and cursors. So, I modified autoform ArrayTracker and added a This solves a lot of performance issues and makes the forms more responsive. It also makes form submits faster. So, now, there are two ways to put this in autoform. First one is forking/cloning and maintaining an independent copy of autoform. Second one is monkey patching arrayTracker. I'm against the second one because it's a little hacky. I'm planning to go the first way, because autoform isn't getting any updates from aldeed anyways, at least this way we can fix the issues we may face in the future. This solves the following issues:
And possibly others. |
I am only now getting the time to look at this properly, and need it for a project as well. I was noticing AutoForm going stale - too bad. I use AutoForm a lot and will offer to try and help maintain on your fork as well. I will test your array work today and give feedback. |
I notice an issue with Text fields inside arrays. They are not showing their labels... and typing in them does not update the summary in the collapsible header (only the first letter). This happens with original AutoForm, as well as the fork. new SimpleSchema({
labelString: {
type: String,
label: 'I am a label.',
optional: true
},
placeholderString: {
type: String,
optional: true,
label: 'I am also a label.',
autoform: {
placeholder: 'I am a placeholder.'
}
},
arrayOfStrings: {
type: Array,
minCount: 1,
maxCount: 3,
optional: true // but, but, with a min or max count it aint optional?
},
'arrayOfStrings.$': {
type: String,
label: 'A string field with placeholder',
autoform: {
placeholder: 'Placeholder'
}
}
} |
Oops... Actually, that is not a bug ... its the same in the current version. Individual labels of an item of an array are shared by the collapsible header. |
Hi @mozfet |
a) the array thing (to use minimongo collections instead of arrays for tracking) I'll fix bugs as I find them. |
Please see previous post... the label not showing for the text field is not a bug but per design, however the default label header of the collapsible does not update automatically for String (only first letter). |
I fixed the header issue in pouya-eghbali/meteor-autoform-materialize@d07e0dd |
The current implementation of quickfield for nested arrays (and arrays in general) results in messy user interfaces, ala:

This needs to improve, and in order to improve, less data needs to be shown at any given time, and a hide and show strategy needs to be used. This will allow arrow rows to become smaller to enable effective drag and drop sorting.
We need to make array input to a more compact format, something like this, combined with some form of a collapsible part to display the content of the current level:

The text was updated successfully, but these errors were encountered: