Last active
December 18, 2015 22:29
-
-
Save nclundsten/5854944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
function countryProvinces(province, country) | |
{ | |
//zf2 select options dont allow non-standard attributes.. hooray. | |
opts = $(province).children('optgroup').each(function(){ | |
$(this).attr('data-country_code', $(this).children().val().substring(0,2)); | |
}); | |
$(province).data('options', opts); | |
$(province).children('optgroup').remove(); | |
$(country).data('province', province); | |
updateProvince = function(province, countryCode) { | |
$(province).val(0) | |
$(province).children('optgroup').remove(); | |
$(province).data('options').each(function(){ | |
if ($(this).data('country_code') == countryCode) { | |
$(province).append(this); | |
} | |
}) | |
} | |
//on change of country, update province element to show provinces that match the country | |
$(country).change(function() { | |
updateProvince($(this).data('province'), $(this).val()); | |
}); | |
updateProvince(province, $(country).val()); | |
} | |
}) (jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment