75 lines
2.2 KiB
JavaScript
Executable File
75 lines
2.2 KiB
JavaScript
Executable File
$(document).ready(function()
|
|
{
|
|
bindStateInputAndUpdate();
|
|
});
|
|
|
|
function bindStateInputAndUpdate()
|
|
{
|
|
|
|
// $('#id_state').selectBox('destroy');
|
|
$('.id_state, .dni, .postcode').css({'display':'none'});
|
|
updateState();
|
|
updateNeedIDNumber();
|
|
updateZipCode();
|
|
|
|
$('select#id_country').change(function(){
|
|
updateState();
|
|
updateNeedIDNumber();
|
|
updateZipCode();
|
|
|
|
});
|
|
|
|
if ($('select#id_country_invoice').length !== 0)
|
|
{
|
|
$('select#id_country_invoice').change(function(){
|
|
updateState('invoice');
|
|
updateNeedIDNumber('invoice');
|
|
updateZipCode('invoice');
|
|
});
|
|
updateState('invoice');
|
|
updateNeedIDNumber('invoice');
|
|
updateZipCode('invoice');
|
|
}
|
|
|
|
// $('#id_state').selectBox();
|
|
// $('#id_state').selectBox('create');
|
|
}
|
|
|
|
function updateState(suffix)
|
|
{
|
|
$('select#id_state'+(suffix !== undefined ? '_'+suffix : '')+' option:not(:first-child)').remove();
|
|
var states = countries[$('select#id_country'+(suffix !== undefined ? '_'+suffix : '')).val()];
|
|
if(typeof(states) !== 'undefined')
|
|
{
|
|
$(states).each(function (key, item){
|
|
$('select#id_state'+(suffix !== undefined ? '_'+suffix : '')).append('<option value="'+item.id+'"'+ (idSelectedCountry === item.id ? ' selected="selected"' : '') + '>'+item.name+'</option>');
|
|
});
|
|
$('.id_state'+(suffix !== undefined ? '_'+suffix : '')+':hidden').fadeIn('slow');;
|
|
}
|
|
else
|
|
$('.id_state'+(suffix !== undefined ? '_'+suffix : '')).fadeOut('fast');
|
|
|
|
$('#id_state').selectBox('destroy');
|
|
$('#id_state').selectBox();
|
|
|
|
// $('#id_state').next().remove();
|
|
}
|
|
|
|
function updateNeedIDNumber(suffix)
|
|
{
|
|
var idCountry = parseInt($('select#id_country'+(suffix !== undefined ? '_'+suffix : '')).val());
|
|
if ($.inArray(idCountry, countriesNeedIDNumber) >= 0)
|
|
$('.dni'+(suffix !== undefined ? '_'+suffix : '')+':hidden').fadeIn('slow');
|
|
else
|
|
$('.dni'+(suffix !== undefined ? '_'+suffix : '')).fadeOut('fast');
|
|
}
|
|
|
|
function updateZipCode(suffix)
|
|
{
|
|
var idCountry = parseInt($('select#id_country'+(suffix !== undefined ? '_'+suffix : '')).val());
|
|
if (countriesNeedZipCode[idCountry] !== 0)
|
|
$('.postcode'+(suffix !== undefined ? '_'+suffix : '')+':hidden').fadeIn('slow');
|
|
else
|
|
$('.postcode'+(suffix !== undefined ? '_'+suffix : '')).fadeOut('fast');
|
|
}
|