onchange > custom Object properties

This commit is contained in:
Cappy Popp 2021-01-06 13:41:08 -05:00
parent daea4892ad
commit 5e193f6d18

View File

@ -11,9 +11,16 @@
newInput.style.left = '-999em'; newInput.style.left = '-999em';
newInput.setAttribute('name', tagName + '-flag'); newInput.setAttribute('name', tagName + '-flag');
newInput.setAttribute('type', 'text'); newInput.setAttribute('type', 'text');
newInput.setAttribute('id', tagName + '-flag'); newInput.setAttribute('id', tagName + '-flag');
newInput.onchange = onChangeHandler;
newInput.style.display = 'none'; newInput.style.display = 'none';
newInput._value = newInput.value;
Object.defineProperty(newInput, "value", {
get: function() { return this._value; },
set: function(v) {
this._value = v;
onChangeHandler(v);
}
});
hiddenLinkedInInputs.appendChild(newInput); hiddenLinkedInInputs.appendChild(newInput);
fillScript.setAttribute('data-field-' + tagName, tagName + '-flag'); fillScript.setAttribute('data-field-' + tagName, tagName + '-flag');
}; };
@ -44,11 +51,11 @@
// [2] To allow us to map the ISO country code LinkedIn provides us // [2] To allow us to map the ISO country code LinkedIn provides us
// to the [sigh] full-text version of the country our select element // to the [sigh] full-text version of the country our select element
// requires // requires
hiddenInputCreator('email', function () { hiddenInputCreator('email', function (newValue) {
// fire the GA event for autofill // fire the GA event for autofill
}); });
hiddenInputCreator('country', function () { hiddenInputCreator('country', function (newValue) {
console.log(this.id + " changed!"); console.log("%s value changed to %s", this.ID, newValue);
// map to the country we have in our select dropdown // map to the country we have in our select dropdown
var countries = { var countries = {
US: 'United States', US: 'United States',
@ -253,7 +260,7 @@
}, },
country = document.querySelector("#Country"); country = document.querySelector("#Country");
// sets the value in the form the user can see // sets the value in the form the user can see
country.value = countries[this.value.toLowerCase()]; country.value = countries[newValue.toLowerCase()];
}); });
/*['email', 'country'].forEach(function(inputField){ /*['email', 'country'].forEach(function(inputField){