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

Make list items sortable #4

Open
jankapunkt opened this issue Nov 20, 2019 · 12 comments
Open

Make list items sortable #4

jankapunkt opened this issue Nov 20, 2019 · 12 comments

Comments

@jankapunkt
Copy link

I currently use a custom extension to make list entries sortable. However, I think it should not be that big issue to provide some [ ⬆️ ] and [ ⬇️ ] buttons to make list items sortable by incrementing / decrementing indices. This solution could also be implemented without any third party lib.

@pouya-eghbali
Copy link
Owner

pouya-eghbali commented Nov 20, 2019

I've added a AutoForm.setFieldValue(fieldName, value, formId) method. I'll investigate if it's possible to getFieldValue, swap elements, and then setFieldValue to achieve this. I also need this functionality, I've modified how arrays work in autoform, idk if it's better to use setFieldValue or to add some magic to the arrayTracker.

@pouya-eghbali
Copy link
Owner

Ok, getFieldValue doesn't work for Arrays, and setFieldValue doesn't work for Arrays and Objects. I'll fix these issues ASAP because I depend on them.

@pouya-eghbali
Copy link
Owner

c914c2b should fix getFieldValue

@pouya-eghbali
Copy link
Owner

6969d6d should fix setFieldValue

This works as long as there isn't any weird fields in the array! In my tests this works for swapping arrays of objects with selects and simple text inputs, but doesn't work with material time and date inputs. Needs more work.

pouya-eghbali added a commit that referenced this issue Nov 27, 2019
@pouya-eghbali
Copy link
Owner

208d2dd Fixes everything, setFieldValue works perfectly, and array items are now swappable/sortable.

@pouya-eghbali
Copy link
Owner

@jankapunkt items can be swapped like this now:

const [item1, item2] = AutoForm.getFieldValue(fieldName, formId)
AutoForm.setFieldValue(fieldName, [item2, item1], formId)

This will make it a lot easier to provide [ ⬆️ ] and [ ⬇️ ] buttons. More fancy stuff are also possible now:

const items = AutoForm.getFieldValue(fieldName, formId)
const sortedItems = items.sort(mySortFunction)
AutoForm.setFieldValue(fieldName, sortedItems, formId)

@jankapunkt
Copy link
Author

Do you think it makes sense then to let extensions implement this? I think it is now flexible enough to let developers imement their own version of up / down / sort. Wdyt?

@jankapunkt
Copy link
Author

Sorry forget my previous comment, extensions can override it anyway so out-of-the-box up/down would still make most sense IMO.

@pouya-eghbali
Copy link
Owner

up/down in templates? or as an API method that extensions can use to implement the functionality?

@jankapunkt
Copy link
Author

Hi. I think it makes sense to provide up down buttons out-of-the box in the default array template, don't you think? The API methods would still be required for this and then extensions could either ignore it or use it to implement e.g. drag and drop etc.

I can work towards a PR if you wan.

@pouya-eghbali
Copy link
Owner

In the default bootstrap and plain templates?

@pouya-eghbali
Copy link
Owner

@jankapunkt I redid the setFieldValue method, it had some issues. I think it works better now, but it's still not perfect.

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