Bug 1370475 - Part 3: Add a custom field "-moz-street-address-one-line" for popup label and filling street-address. r=lchang

MozReview-Commit-ID: Jh178WQZ5Qs

--HG--
extra : rebase_source : d2357397445a0671afa7d7f7e8aa5b7f675bf93f
This commit is contained in:
Sean Lee 2017-06-21 09:47:10 +08:00
parent 7c64597fd1
commit 4d0a1eba3b
4 changed files with 22 additions and 4 deletions

View File

@ -125,7 +125,14 @@ FormAutofillHandler.prototype = {
_addressTransformer(profile) {
if (profile["street-address"]) {
profile["street-address"] = this._getOneLineStreetAddress(profile["street-address"]);
// "-moz-street-address-one-line" is used by the labels in
// ProfileAutoCompleteResult.
profile["-moz-street-address-one-line"] = this._getOneLineStreetAddress(profile["street-address"]);
let streetAddressDetail = this.getFieldDetailByName("street-address");
if (streetAddressDetail &&
(streetAddressDetail.elementWeakRef.get() instanceof Ci.nsIDOMHTMLInputElement)) {
profile["street-address"] = profile["-moz-street-address-one-line"];
}
let waitForConcat = [];
for (let f of ["address-line3", "address-line2", "address-line1"]) {

View File

@ -143,6 +143,10 @@ ProfileAutoCompleteResult.prototype = {
allFieldNames.includes(currentFieldName);
if (matching) {
if (currentFieldName == "street-address" &&
profile["-moz-street-address-one-line"]) {
return profile["-moz-street-address-one-line"];
}
return profile[currentFieldName];
}
}
@ -155,8 +159,13 @@ ProfileAutoCompleteResult.prototype = {
return profiles.filter(profile => {
return !!profile[focusedFieldName];
}).map(profile => {
let primaryLabel = profile[focusedFieldName];
if (focusedFieldName == "street-address" &&
profile["-moz-street-address-one-line"]) {
primaryLabel = profile["-moz-street-address-one-line"];
}
return {
primary: profile[focusedFieldName],
primary: primaryLabel,
secondary: this._getSecondaryLabel(focusedFieldName,
allFieldNames,
profile),

View File

@ -45,14 +45,15 @@ const TESTCASES = [
],
profileData: {
"guid": "123",
"street-address": "2 Harrison St",
"street-address": "2 Harrison St line2",
"-moz-street-address-one-line": "2 Harrison St line2",
"address-level2": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
expectedResult: {
"street-addr": "2 Harrison St",
"street-addr": "2 Harrison St line2",
"city": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",

View File

@ -24,6 +24,7 @@ let matchingProfiles = [{
guid: "test-guid-3",
organization: "",
"street-address": "321, No Name St. 2nd line 3rd line",
"-moz-street-address-one-line": "321, No Name St. 2nd line 3rd line",
"address-line1": "321, No Name St.",
"address-line2": "2nd line",
"address-line3": "3rd line",