-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Afform - Quick add links for Autocomplete fields #27754
Conversation
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
Exciting work, @colemanw! If I read the code correctly, the main thing that's still missing is, within the FormBuilder admin ui, the configuration of "quick-add" for entityref fields. |
I still want to advocate for allowing admins to override the default quick-add form. An example use case:
I think making this possible wouldn't be too hard. As you code the UI for configuring quick-add on entityref fields, you'd just need to provide options for "default" (which would be When it comes to rendering the afform, if non-default quick-add forms have been selected, they'd need to be prepended to |
@highfalutin I had to go chase a couple rabbits down their holes before coming back to this. But now that #27553 and #27659 and #27713 are merged I've rebased & completed work on this PR and it's working pretty well.
Your wish is granted. 🧞 I'll update the description with a step-by-step. Let me know when you get a chance to review. |
Retest this please |
3b4495f
to
7a9d50d
Compare
retest this please |
1 similar comment
retest this please |
Wow Jenkins has really been having a bad week. |
Testing this locally, I am able to create an afform (A1), add an Existing Contact field, and select "New Individual" as the quick-add form for that field. However, when I open the rendered afform A1 and click the "New Individual" button, the modal form that opens is another copy of the same form A1 -- not a New Individual form. |
Hmm, ok let's get a new online demo going. @civicrm-builder retest this please |
}) | ||
// Pop-up Afform when clicking quick-add links | ||
.on('click.crmEntity', '.crm-entityref-quick-add a', () => { | ||
let url = $(this).attr('href'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let url = $(this).attr('href'); | |
let url = $('#select2-drop .crm-entityref-quick-add a').attr('href'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, in my testing, this
was referring to the wrong element. Changing this line fixes the quick-add behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... except when multiple quick-add buttons are configured, it only respects the first one. Hmmmm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@highfalutin Aha! I found "some reason" - it's because arrow functions behave differently than regular functions with this
binding.
Fixed now, thanks for the hint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this works for multiple quick-add buttons:
let url = $(this).attr('href'); | |
let url = $(event.target).attr('href'); |
afforms for testing[ { "requires": [], "title": "Event Registration with Quick Add", "description": "", "is_public": false, "permission": [ "access CiviCRM" ], "type": "form", "entity_type": null, "join_entity": null, "placement": [], "summary_contact_type": null, "summary_weight": null, "icon": "fa-list-alt", "server_route": "civicrm/reg", "permission_operator": "AND", "redirect": null, "submit_enabled": true, "submit_limit": null, "create_submission": true, "navigation": { "parent": null, "label": "Event Registration with Quick Add", "weight": 0 }, "name": "afformEventRegistrationWithQuickAdd", "layout": [ { "#tag": "af-form", "ctrl": "afform", "#children": [ { "#text": "\n " }, { "#tag": "af-entity", "data": { "status_id": "1", "event_id": "1", "role_id": [ "1" ] }, "actions": { "create": true, "update": false }, "type": "Participant", "name": "Participant1", "label": "Participant 1", "security": "RBAC" }, { "#text": "\n " }, { "#tag": "fieldset", "af-fieldset": "Participant1", "class": "af-container", "af-title": "Participant 1", "#children": [ { "#text": "\n " }, { "#tag": "af-field", "name": "contact_id", "defn": { "input_attrs": { "quickAdd": "civicrm/quick-add/Individual/with-phone-email" } } }, { "#text": "\n " }, { "#tag": "button", "class": "af-button btn btn-primary", "crm-icon": "fa-check", "ng-click": "afform.submit()", "#children": [ { "#text": "Submit" } ] }, { "#text": "\n " } ] }, { "#text": "\n" } ] }, { "#text": "\n" } ] }, { "requires": [], "title": "New Individual Phone Email", "description": "", "is_public": false, "permission": [ "access CiviCRM" ], "type": "form", "entity_type": null, "join_entity": null, "placement": [], "summary_contact_type": null, "summary_weight": null, "icon": "fa-list-alt", "server_route": "civicrm/quick-add/Individual/with-phone-email", "permission_operator": "AND", "redirect": null, "submit_enabled": true, "submit_limit": null, "create_submission": true, "navigation": null, "name": "afformNewIndividualPhoneEmal", "layout": [ { "#tag": "af-form", "ctrl": "afform", "#children": [ { "#text": "\n " }, { "#tag": "af-entity", "data": { "contact_type": "Individual", "source": "New Individual Phone Email" }, "type": "Contact", "name": "Individual1", "label": "Individual 1", "actions": { "create": true, "update": true }, "security": "RBAC" }, { "#text": "\n " }, { "#tag": "fieldset", "af-fieldset": "Individual1", "class": "af-container", "af-title": "Individual 1", "#children": [ { "#text": "\n " }, { "#tag": "af-field", "name": "first_name" }, { "#text": "\n " }, { "#tag": "af-field", "name": "last_name" }, { "#text": "\n " }, { "#tag": "div", "af-join": "Email", "af-repeat": "Add", "af-copy": "Copy", "min": "1", "#children": [ { "#text": "\n " }, { "#tag": "afblock-contact-email" }, { "#text": "\n " } ] }, { "#text": "\n " }, { "#tag": "div", "af-join": "Phone", "af-repeat": "Add", "af-copy": "Copy", "min": "1", "#children": [ { "#text": "\n " }, { "#tag": "afblock-contact-phone" }, { "#text": "\n " } ] }, { "#text": "\n " } ] }, { "#text": "\n " }, { "#tag": "button", "class": "af-button btn btn-primary", "crm-icon": "fa-check", "ng-click": "afform.submit()", "#children": [ { "#text": "Submit" } ] }, { "#text": "\n" } ] }, { "#text": "\n" } ] } ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are also needed; otherwise buttons for all afforms under "civicrm/quick-add/X" are shown.
} | ||
let markup = '<div class="crm-entityref-links crm-entityref-quick-add">'; | ||
CRM.config.quickAdd.forEach((link) => { | ||
if (quickAddLinks.includes(link.path)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (quickAddLinks.includes(link.path)) { | |
if (_.includes(quickAddLinks, link.path)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to use more vanilla and less lo-dash recently, as that seems to be the direction the whole internet is headed. Did you find a bug here or is it just a style thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I found the cause - quickAddLinks is a string but was supposed to be an array. One sec...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I made the Line 580 suggestion.
multiple = !!select2Options.multiple; | ||
const $el = $(this).off('.crmEntity'); | ||
let staticItems = getStaticOptions(select2Options.static), | ||
quickAddLinks = select2Options.quickAdd, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quickAddLinks = select2Options.quickAdd, | |
quickAddLinks = select2Options.quickAdd ? select2Options.quickAdd.split(',') : [], |
@highfalutin thanks for patiently testing this. I've fixed the array formatting, the |
Thanks @colemanw! The last bug we were talking about still needs to be fixed. At js/Common.js line 580, The reason I propose |
I think that might just be your existing test forms. If you regenerate those with the updated patch I've fixed the Afform GUI to always set that value as an array.
I'm not quite sure what you mean... that link shows green for every browser except IE. I think we've pretty much given up on maintaining IE support. |
Ah, ok, I re-tested and am no longer seeing the bug. My bad re: |
The last test I did was whether quick-adds could be used within quick-adds. And they can! IMO this can be merged. |
Overview
APIv3-based EntityRef fields have quick-add buttons which link to profile forms (e.g. "New Individual"). This implements a similar feature for the newer APIv4-based Autocomplete fields, using Afforms instead of Profiles.
See https://lab.civicrm.org/dev/core/-/issues/4484
Usage
Technical Details
For lack of anything fancier, the "quick-add" forms are identified by their route: any form with a route starting with "civicrm/quick-add" is automatically available in the dropdown pictured in step 3 (if the entity type matches).
This makes it quite configurable/flexible. You can make as many quick-add forms as you wish, to suit different types of Autocomplete fields.