Skip to content

Instantly share code, notes, and snippets.

@brooke-heaton
Last active May 2, 2017 03:40
Show Gist options
  • Save brooke-heaton/b03affc48cdb6794370f3010347b468e to your computer and use it in GitHub Desktop.
Save brooke-heaton/b03affc48cdb6794370f3010347b468e to your computer and use it in GitHub Desktop.
Conditionally Hide Subfields in Drupal 8 Webform Address Elements
(function ($, Drupal) {
'use strict';
Drupal.behaviors.registration_form = {
attach: function (context) {
// Conditionally hide the city/state unless user chooses United States.
$("#edit-address-country").change(function () {
if ($("#edit-address-country").val() === "United States") {
$('.form-item-address-city').show();
$('.form-item-address-state-province').show();
}
else {
$('.form-item-address-city').hide();
$('.form-item-address-state-province').hide();
}
});
}
}
}(jQuery, Drupal));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment