This seems to be a problem with the way we classify an address element ( input, select ). In _findMatchedFieldName we loop through all regex rules for different address parts ( country, state, address-level-*) and then return when an element's identifiers ( id, name, label ) matches the current rule.
The problem is we return the moment an identifier matches a rule.
In amazon's case the country select has the following identifiers:
Since we loop over the regex first and try to match we end up matching the
label: Country / Region to
address-level1 regex for
address-level1 macthes the
region part, which is wrong. It will cause the select to be updated with the value stored for
address-level1 ( state ) instead of country.
We can switch the order of the loops, so we prioritize id and name before label, or order the regex rules differently, so as to prioritize country, but we will still encounter the same problem as before in some other edge case. A simple solution would be to match all the descriptors and see the most frequent one. In the case of amazon that would be country since:
Country/Region will match
address-ui-widgets-countryCode-dropdown-nativeId will match
address-ui-widgets-countryCode will match
This would be a start to improve the matching, but we will still need to handle some other edge cases ( same frequencies ... ).
:serg :dimi what do you think about this ?