-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
Fix Field mapping bug - forgets related fields #23534
Conversation
(Standard links)
|
0f8ce5a
to
13be8cc
Compare
I see you've pushed more changes - those results were from before that push. |
@aydun no - just a rebase - there weren't any changes in it - just keeping it fresh |
@aydun I'm assuming your anomaly is unchanged by this PR? |
CRM/Contact/Import/Form/MapField.php
Outdated
foreach ([1, 2, 3] as $columnNumber) { | ||
if (empty($mapperValues[$columnNumber])) { | ||
$rowNumber = str_replace('mapper[', '', substr($row, 0, -1)); | ||
$js[] = "cj('#mapper_{$rowNumber}_{$columnNumber}').hide();"; |
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.
Isn't 'cj' deprecated? How about:
$js[] = "CRM.\$('#mapper_{$rowNumber}_{$columnNumber}').hide();";
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.
yeah - I'm always confused about that - it doesn't seem to work on some pages - @colemanw what should I use (Or are we just happy with 'a bit better' here?)
Yes - this also happens without this PR. I just noticed it while testing this, so not a problem for this PR. |
@aydun I think the 'Primary' behaviour is better - so I might yet circle round to that (not necessarily in this PR) |
} | ||
else { | ||
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n"; | ||
if ($hasColumnNames) { | ||
// do array search first to see if has mapped key | ||
$columnKey = array_search($this->_columnNames[$i], $this->getFieldTitles()); |
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.
Not sure how to do a PR on a PR ... but the line just below this that reads:
$defaults["mapper[$i]"] = $columnKey;
can be changed to:
$defaults["mapper[$i]"] = [$columnKey];
to avoid the problem on the initial display of the mapping page that I noted.
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.
@aydun - I can add that in - but do you want to confirm if it works with the other change you suggested? - if so I can include that too
(I think you can actually suggest changes in review & I can commit them through th eUI too)
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.
@aydun well I've pushed up tht change - so no pressure on checking the other
13be8cc
to
b7834b2
Compare
See: eileenmcnaughton#14 |
84ac07a
to
51f2502
Compare
@aydun - I merged your commit in & rebased to cheer up Jenkins - but now it's defaulting to 'Home' for both rather than 'Primary' for both |
I'll try again |
51f2502
to
c0426f6
Compare
@aydun - OK it IS showing 'Primary' for main contact - but when I changed 2 fields to related I got 'Home' |
c0426f6
to
bad6fcf
Compare
if (!empty($sel2[$key]) && is_array($sel2[$key])) { | ||
reset($sel2[$key]); | ||
$subkey = key($sel2[$key]); | ||
$def[] = $subkey; |
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 think "Primary" is set here when the form is first loaded and the mapping is guesstimated. But after the form is built there is no default set for $sel2 so "Home" is selected as that is the first item in the select list.
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.
The options are created via JS here: https://github.com/civicrm/civicrm-packages/blob/96b7c2441b851395176bb275a45e24fbe31e3187/HTML/QuickForm/hierselect.php#L427
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 just rebased this - do you see a fix for ^^ @darrick - it was kind of a tangent on this PR - so I'm also happy to drop that bit out of scope for this PR
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 think "Primary" is set here when the form is first loaded and the mapping is guesstimated.
Yes, 'Primary' is selected because it is first in the php list.
When you change to a relationship ('spouse of') then the JS `swapoptions()' function is called. No value is initially set so the dropdown shows the first option.
The array ordering in php is:
"Primary":"Primary",
"5":"Billing",
"1":"Home",
"3":"Main",
"4":"Other",
"2":"Work"
However, although the php values are passed in the same order, when the JS function loops through the array to add the select options, it does so based on the ordering of the keys, not the order added, and so the options are ordered as:
1: "Home"
2: "Work"
3: "Main"
4: "Other"
5: "Billing"
Primary: "Primary"
To fix the default, we could explicitly pass through a default value and use that when creating the select options in swapoptions()
If we wanted to solve the more general issue of making the JS options match the PHP order, I think we would need to assign new key values when we pass from PHP to JS, but then also map back from from JS keys to PHP keys. That sounds like a lot of effort for something few people are likely to notice!
This looks like it goes well beyond the scope of the initial aim of this PR.
bad6fcf
to
1ab060d
Compare
default mappings. Use CRM.$ instead of cj for new jQuery Fix an assignment to $this->fieldUsed. Not sure why it exists but lets update the right key.
1ab060d
to
11ed05c
Compare
@colemanw - this should be mergeable based on ^^ - ie this is an agreed fix - discussion focusses on a tangential bug that came up in review |
This is a bit out of my skill set. But most things are. But I did step through the code a bit the other night. To me it seemed like setDefault was for setting form defaults when the page is first loaded. And this bug has more to do with the form state being lost or mangled when hitting the back button. Also, the csv file used for testing has duplicate header field. I recall theleague/cvs throws an error for that. Maybe that should be caught in Validation earlier. I just tested real quick. If I do the following (i.e. just don't set any defaults if the mapper is set). Then it works fine except the extra selects not be hidden. This is based off master.
|
The following solves the problem on my end: c9cd1c1 Adding this For what @aydun is mentioning about having a default location type maybe the swapOption js could be modified to use a default as it's currently hardcoded to false. Setting it in buildForm will only work for inferred defaults. |
Overview
Fix Field mapping bug - forgets related fields
I hit this during r-run on imports and initially thought it was a regression but it is there in 5.48 too.
To replicate
Before
After
Technical Details
I think I got to the bottom of what the js was doing & switched to a simple jquery hide (well a whole tonne of them - I'm sure it could be more elegant at the jquery end but figuring out this much was a lot....
Comments