0

I am looking for a way to make HABTM relations on the website more beautiful. By default, these are displayed in a long list. To select several at once, one has to hold Ctrl.

I could imagine something like a drag and drop system with two tables next to each other. Everything in the right table is considered selected. https://i.stack.imgur.com/vRWYE.jpg

Unfortunately, I'm not sure how to do it well. My only approach so far would be to automatically create a table from cakephp and create a second empty table.

If the page is opened, a javascript would hide everything in the cakephp table that is not selected (that would be the right table). In the still empty table the script would then write everything that was hidden from the other.

If you now click on one of the objects in one of the table, javascript would hide it in this table and show it in the other and (de-)select it.

This implementation sounds rather difficult and error-prone to me. Do you have any good ideas what I could do here? Possibly a plugin or something in the direction? Unfortunately I could not find anything about this in my search. But I can not imagine that no one has dealt with the issue, since the HABTM representation of cakephp is not that good.

ndm
  • 59,784
  • 9
  • 71
  • 110
Carsten
  • 45
  • 9
  • Use select2 or one of it's versions for whatever JS framework you might use. And what you show in your screenshot is *really* not hard to get done with a few lines of jquery and some AJAX to fetch JSON data. – floriank Aug 06 '18 at 13:39
  • https://sandbox.dereuromark.de/sandbox/tags/select shows another option, but maybe not for super large lists. – mark Aug 07 '18 at 09:20
  • Hey @burzum, thanks for your respond. I feel a bit ashamed. But i do not understand how i can use select2 to accomplish my goals. My current plan was to use as much of cakephp as i can. So AJAX should not be needed. I would like my new list visualisation to be included in the cakephp submit form. But i am probably also too bad in googling this stuff. I am not sure how this kind if lists are named. Could you give me some hints (like how i could accomplish the lists) or links to something like a tutorial? – Carsten Aug 07 '18 at 16:01
  • Hey @mark, thank you for this example, but my lists will be too large for this. – Carsten Aug 07 '18 at 16:02
  • Cake can't do everything for you. If you need to use JavaScript or Ajax to get the results you desire, then use JavaScript or Ajax. The technologies are very complementary. – Greg Schmidt Aug 09 '18 at 05:15

0 Answers0