Skip to main content

๐Ÿ“ฎ Change Country Field Default on an Address Block

Address blocks default the Country field to United States ๐Ÿ‡บ๐Ÿ‡ธ. What a particular form is targeted to international students? ๐ŸŒ

You can change the default country for your entire Slate instance under Database > Configuration keys, but some items may still default to US as ofย September 2023.

Place any of the following code examples you want to use into theย form scripts box.

Pre-Set Country to Blank

// Wait for the page to finish loading
$(window).on("load", function () {
    // Set the Country field to blank
    $("[data-export='sys:address'] [name$='_country']").val('');
    // Trigger change handler to update the region list
    $("[data-export='sys:address'] [name$='_country']").change();
});

Pre-Set Country to Canada ๐Ÿ‡จ๐Ÿ‡ฆ

// Wait for the page to finish loading
$(window).on("load", function () {
    // Set the Country field to blank
    $("[data-export='sys:address'] [name$='_country']").val('CA');
    // Trigger change handler to update the region list
    $("[data-export='sys:address'] [name$='_country']").change();
});

The list of country codes can be found in the HTML source of the form. It appears to follow the ISO 3166-1 alpha-2 list.

Move United States to the Top

// Wait for the page to finish loading
$(window).on("load", function () {
	// Move US to top
	$("[data-export='sys:address'] option[value='US']").insertBefore($("[data-export='sys:address'] option:eq(0)"));
});

Prevent Editing Country Field

$(window).on("load", function () {
  $('#').disable().attr("data-disabled", "1").css({
    border: "1px solid rgb(204, 204, 204)",
    color: "rgb(102, 102, 102)"
  });
});