Skip to content

Instantly share code, notes, and snippets.

@nclundsten
Created June 24, 2013 22:56
Show Gist options
  • Save nclundsten/5854476 to your computer and use it in GitHub Desktop.
Save nclundsten/5854476 to your computer and use it in GitHub Desktop.
function filterProvinces(element, countryCode) {
$(element).val(0);
optGroups = $(element).data('options');
$(optGroups).each(function(){
var match = false
if ($(this).data('country_code') == countryCode) {
$(element).append($(this));
}
})
$(element).find('optgroup').remove();
}
$(document).ready(function(){
province = $("select[name=province]");
opts = $(province).find('optgroup').each(function(){
//zf2 doesnt allow non-standard option attributes.. hooray.
$(this).attr('data-country_code', $(this).children().val().substring(0,2));
});
console.log(opts);
$(province).data('options', $(opts)); //store as data val
$(province).find('optgroup').remove(); //remove the elements
$("select[name=country]").live('change', function() {
province = $(this).siblings("select[name=province]");
val = $(this).val();
filterProvinces(province, val)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment