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

Afform - Fix broken prefill functionality #27121

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Aug 22, 2023

Overview

Fixes multiple bugs when autocompleting an existing entity.

Before

  • When using a repeating entity (e.g. multiple contacts), only the first one could be autofilled.
  • Autofilling a repeating entity would trigger an endless loop in js.
  • Recent regression caused form fields to not be correctly cleared when deselecting existing entity

After

Fixed

Comments

Simplest way to reproduce the bug is to make a new form with all the defaults, enable "Repeat" for Individual1 (top-right of the fieldset in the layout) and drag in "Existing Contact" field to Individual1.
Give the form a title and url, save, and try out the form. As soon as you try to autocomplete a contact it enters an endless js loop.
Refresh the form to see the other bug: Click the "+ Add" button and try to autocomplete the 2nd contact. It will fill the wrong one (also enter another endless loop).

@civibot
Copy link

civibot bot commented Aug 22, 2023

Thank you for contributing to CiviCRM! ❤️ We will need to test and review the PR. 👷

Introduction for new contributors
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers

@civibot civibot bot added the master label Aug 22, 2023
Before: Index was ignored so only the first entity in an af-repeat set could be autofilled
After: Index handled correctly
Before: Objects overwritten, breaking references and causing endless loops
After: Objects merged correctly
@seamuslee001
Copy link
Contributor

I tested this on my local and was able to replicate the issue and confirmed this fixed the problem

@seamuslee001 seamuslee001 merged commit b588537 into civicrm:master Aug 24, 2023
@seamuslee001 seamuslee001 deleted the afformPrefill branch August 24, 2023 02:15
@GitHub-user-29
Copy link

GitHub-user-29 commented Aug 27, 2023

@colemanw, @seamuslee001
I have tested on dmaster (5.66.alpha1), and the infinite loops seems to be solved, autocomplete is working fine 👍
BUT I have the impression something that was working before no longer works.
In my answer (based on your help), I explained that it was possible to autofill multiple parents (individual 2) of multiple children (individual 1) . This is not working on 5.66.alpha1

Use case : a form showing a family (parents and all their children).
Individual 1 = autofill as child of current user. Repeating. (we want to display all the children of current user)
Individual 2 = autofill as parent of Individual1. Repeating. (we want to display all the parents, which are at least "Current user" and possibly someone else if existing in CRM)
We have parent/child relation, but NOT "partner of" between parents

Behaviour on 5.66.alpha 1:
Individual 2 shows only Current user, and not the second parent of Individual 1
I have also created a "partner of" relation between both parents, with edit permissions (suspecting a permission problem), but it did not change anything.

EDIT : Individual 1 show only 1 child, although it is set as repeating and the relation is correctly created.

Screenshots :
Children
image

PARENTS
image

Relation
image

Homer is the current user, and parent of 2 children.
Marge is also parent of the same 2 children.
image

Here we should see 2 children, not just one. And also Marge as the second parent
image

@colemanw
Copy link
Member Author

@GitHub-user-29 thanks for the detailed description and screenshots. Can you review this fix: #27615

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.

3 participants