I am building a classified ads platform (like Gumtree/Craigslist), where users can submit ads - and where an ad can have multiple images associated with it.
So I have a data type called ‘Item’, which has a field called Images which is a list of images:
My question is - How do I allow my users to control the order of the images? I’d like to allow them to go into an ‘Edit Ad’ page and see the images they have already added (which I assume are ordered in the order in which they uploaded them by default) - and then change the order. It could be drag/drop or clicking an arrow to change the order (like this) - I don’t mind at this stage!
All the questions and answers I’ve seen on this forum to do with reordering a repeating group assume that you are displaying a repeating group where each cell is a type rather than displaying a field list from a type (i.e. if I had Images as a type, rather than a field on a type) - so don’t help my situation.
I’ve tried to play around with setting Custom States, but haven’t yet had any luck.
Happy to set up a publicly available version of the project if any of you think you can help!
I think the easiest way may be to create a new data type…call it advert images…each data entry would have a field for image, a field to store the text value you would use to ‘related it to the advert’ (maybe the adverts ID) as well as field for sort order which would be type number.
Then put on the advert a list of ‘advert images’ and you could then on display sort by the sort order number.
When you want to allow users to re-order the images, set up a drag and drop system inside of a repeating group. Then on saving put the current cells index as the images sort order number.
Just going to throw in another option for you here, to accompany @boston85719 and @cmarchan already great solutions. A while back, I put something together which was similar to what you need, but the user could swap 2 images with one another in a list. It might not be entirely suited but it works with JS and custom states rather than having the sort option as a field in the DB.
Added benefit of being nice and quick, if you can dissect it, maybe it will help.
Just select an Image set and then you drag the images.
It’s a good solution. I bought a permanent license of your plugin, but I can not use it in my application so far because of two reasons:
Changing order of item in table does not change its index. In each table I am useing the expression “Current cell’s Index <-modulo-> 2 is 1” to changing line shading in the table.
In workflow does not contain information about order of changed item.