ux icon indicating copy to clipboard operation
ux copied to clipboard

Proposal: component to handle form collections

Open jmsche opened this issue 4 years ago • 19 comments
trafficstars

It would be nice if there was some available JS in the ux components to add basic stuff to handle form collections (add & remove) :)

jmsche avatar Dec 03 '20 14:12 jmsche

100%. Literally the first thing I thought of when I ready the post was "I wonder if they did this whole initiative just to make UX easier with form collections"

kriskoch avatar Dec 03 '20 14:12 kriskoch

Same for me - form collections were my first thought when hearing about the UX

Has there been any movement on this issue anywhere?

benr77 avatar Jan 30 '21 11:01 benr77

Not yet but we are open to contribs :) !

tgalopin avatar Jan 30 '21 14:01 tgalopin

Hi everyone,

I just made my first Symfony bundle which should meet your need. I would like to develop it further and why not propose it to the community. What do you think ? https://github.com/stakovicz/ux-collection

Here you have the demo code: https://github.com/stakovicz/ux-collection-test

stakovicz avatar Apr 27 '21 19:04 stakovicz

@stakovicz Awesome work - I took a quick look at the bundle and it looks good! I will try and test it out in a project of mine later this week.

benr77 avatar Apr 28 '21 06:04 benr77

@stakovicz I just tested your bundle in an application of mine. At first glance it worked pretty good. Just install, change the form type and you're good to go.

It would be great if we could be able to customize the way entries are added, e.g. if you want to use tables. Otherwise good work. 👍

daFish avatar Apr 28 '21 06:04 daFish

@stakovicz I just tested your bundle in an application of mine. At first glance it worked pretty good. Just install, change the form type and you're good to go.

It would be great if we could be able to customize the way entries are added, e.g. if you want to use tables. Otherwise good work. 👍

Thanks, I'll see what I can do.

stakovicz avatar Apr 28 '21 11:04 stakovicz

Just install, change the form type and you're good to go

This is great! Low entry barrier to using the bundle :)

benr77 avatar Apr 28 '21 13:04 benr77

Hi @tgalopin,

What do you think of my bundle? https://github.com/stakovicz/ux-collection

What would be missing to integrate it into Symfony UX?

stakovicz avatar Apr 30 '21 08:04 stakovicz

Hey @stakovicz !

I didn't have much time to review it in details, but I see that you are already using Symfony UX :) ! The plug and play behavior isn't linked to the Symfony namespace, your bundle already is integrated with Symfony UX.

Regarding putting it under the Symfony namespace, it does seem to be a great fit and a well implemented bundle, I'd be happy to review a PR to add the component.

I'd probably name it UX Form Collection (UX Collection is maybe a it too generic).

tgalopin avatar Apr 30 '21 12:04 tgalopin

Hi @stakovicz,

One thing I think your package is missing is handling an other prototype name than __name__, which can be useful for nested form collections.

jmsche avatar Apr 30 '21 13:04 jmsche

Hey @stakovicz !

I didn't have much time to review it in details, but I see that you are already using Symfony UX :) ! The plug and play behavior isn't linked to the Symfony namespace, your bundle already is integrated with Symfony UX.

Regarding putting it under the Symfony namespace, it does seem to be a great fit and a well implemented bundle, I'd be happy to review a PR to add the component.

I'd probably name it UX Form Collection (UX Collection is maybe a it too generic).

Hi @tgalopin,

Thanks for your support !

I do the changes for the namespace and the name here : https://github.com/stakovicz/ux-collection/commit/e3922b3ed36267de5ecdd35d05919fae902662a5

But I don't know how I can make PR on a bundle that doesn't exist.

stakovicz avatar May 03 '21 09:05 stakovicz

But I don't know how I can make PR on a bundle that doesn't exist.

Create a new folder inside src/ within this repository and copy your bundle inside this folder :-) (The namespace must match, see the composer.json of other bundles inside this monorepo) The src/ folder will be split into individual repos.

richardhj avatar May 03 '21 09:05 richardhj

Thanks @richardhj !

I did my first PR :partying_face:

stakovicz avatar May 03 '21 10:05 stakovicz

One thing I think your package is missing is handling an other prototype name than __name__, which can be useful for nested form collections.

@jmsche you would like to have an attribute to use a custom placeholder __name__ ?

stakovicz avatar May 03 '21 10:05 stakovicz

One thing I think your package is missing is handling an other prototype name than __name__, which can be useful for nested form collections.

@jmsche you would like to have an attribute to use a custom placeholder __name__ ?

I'm not sure I understand the question.

You should be able to pass the prototype name from the Form Type to the view, then it will be available in the form vars, so you can pass it from the view to JS using a data attribute.

I hope it answers your question :)

jmsche avatar May 03 '21 11:05 jmsche

@jmsche I'm not sure about that you want :)

Has you can see here : https://github.com/stakovicz/ux/blob/main/src/FormCollection/Resources/assets/src/controller.js#L62-L68 the __name__ is replace by the index. So you want to manipulate it ?

stakovicz avatar May 03 '21 16:05 stakovicz

The idea is to pass the prototype name from the Form Type to the view and finally to JS like this:

  • In Form Type: add prototype name to view vars in buildView()
  • In template: add a data-{{ controllerName }}-prototype-name attribute with the value coming from view vars
  • In JS: use this data attribute value instead of __name__

jmsche avatar May 04 '21 05:05 jmsche

@jmsche I've removed the hard coded property_name value. I use a Stimulus value passed from the view to the JS.

stakovicz avatar May 04 '21 07:05 stakovicz