Skip to content

Commit

Permalink
Merge pull request #24993 from code-dot-org/country-to-country-code
Browse files Browse the repository at this point in the history
Transform country name to country code upon submitting finish_sign_up…
  • Loading branch information
Madelyn Kasula committed Sep 25, 2018
2 parents ba06b59 + 42857c3 commit a32ff14
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions apps/src/sites/studio/pages/devise/registrations/finish_sign_up.js
Expand Up @@ -15,13 +15,23 @@ const ALL_FIELDS = [...TEACHER_ONLY_FIELDS, ...STUDENT_ONLY_FIELDS, ...SHARED_FI
const scriptData = getScriptData('signup');
const {usIp} = scriptData;

// Auto-fill country in SchoolInfoInputs if we detect a US IP address.
let schoolData = {country: usIp ? 'United States' : ''};
// Auto-fill country and countryCode if we detect a US IP address.
let schoolData = {
country: usIp ? 'United States' : '',
countryCode: usIp ? 'US' : '',
};

$(document).ready(() => {
const schoolInfoMountPoint = document.getElementById("school-info-inputs");
renderSchoolInfo();

$(".finish-signup").submit(function () {
// The country set in our form is the long-form string name of the country.
// We want it to be the 2-letter country code, so we change the value on form submission.
const countryInputEl = $('input[name="user[school_info_attributes][country]"]');
countryInputEl.val(schoolData.countryCode);
});

$("#print-terms").click(function () {
$("#print-frame")[0].contentWindow.print();
});
Expand Down Expand Up @@ -89,7 +99,10 @@ $(document).ready(() => {
}

function onCountryChange(_, event) {
schoolData.country = event ? event.value : '';
if (event) {
schoolData.country = event.value;
schoolData.countryCode = event.label;
}
renderSchoolInfo();
}

Expand Down

0 comments on commit a32ff14

Please sign in to comment.