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

dev/core#398 FormBuilder: add 'Copy' button #26071

Merged
merged 1 commit into from
May 23, 2023
Merged

Conversation

aydun
Copy link
Contributor

@aydun aydun commented Apr 17, 2023

Overview

Extend the FormBuilder 'repeat' functionality to add a button to create a new item with a copy of the previous item's values.
https://lab.civicrm.org/dev/core/-/issues/3986

The use case here is for creating a set of similar entities where most values are the same.

Before

Can 'Add' a new item

After

Can 'Add' a new item, and also 'Copy' to duplicate the previously entered values:

image

Click Copy

image

Then make changes to second entry etc

Technical Details

@colemanw Here's an attempt to produce a 'Copy' button, but it's fairly clueless copy/paste/hack!

This seems to work ok for a simple fieldset as in the screenshots. However, if you create a form for Contact and add the Email block, then the repeat type is 'join' and it fails with duplicates in the ngRepeat, which I think is because of cloneDeep Have you come across that before?

Also, the 'Copy' button appears whenever the 'Add' one does. Do you think it need separate configuration to allow form builders to specify whether 'Copy' is enabled?

Comments

Anything else you would like the reviewer to note

@civibot
Copy link

civibot bot commented Apr 17, 2023

(Standard links)

@civibot civibot bot added the master label Apr 17, 2023
@colemanw
Copy link
Member

it fails with duplicates in the ngRepeat, which I think is because of cloneDeep Have you come across that before?

@aydun yes I have - the problem is that cloneDeep also clones Angular's secret $$id hash which is supposed to be unique. The solution is to use angular.copy() instead of loDash.cloneDeep().

@aydun
Copy link
Contributor Author

aydun commented May 19, 2023

it fails with duplicates in the ngRepeat, which I think is because of cloneDeep Have you come across that before?

@aydun yes I have - the problem is that cloneDeep also clones Angular's secret $$id hash which is supposed to be unique. The solution is to use angular.copy() instead of loDash.cloneDeep().

Thanks @colemanw ! That's fixed it.

One minor thing: the 'Add' and 'Copy' labels are editable, but do not allow spaces so you can configure 'AddEmail' but not 'Add Email'. Where is that restricted?

@aydun aydun changed the title WIP: FormBuilder: add 'Copy' button FormBuilder: add 'Copy' button May 19, 2023
@colemanw colemanw merged commit 04a71a0 into civicrm:master May 23, 2023
@colemanw
Copy link
Member

One minor thing: the 'Add' and 'Copy' labels are editable, but do not allow spaces so you can configure 'AddEmail' but not 'Add Email'. Where is that restricted?

@aydun that's funny, I'm not seeing that problem on my end.

@aydun
Copy link
Contributor Author

aydun commented May 23, 2023

@aydun that's funny, I'm not seeing that problem on my end.

@colemanw I'm getting the problem on Firefox but not Chromium

@aydun aydun changed the title FormBuilder: add 'Copy' button dev/core#398 FormBuilder: add 'Copy' button May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants