Issue #0001787: try to make universal script for using anywhere. (not finalized)

This commit is contained in:
Aram HARUTYUNYAN 2013-12-16 11:10:13 +00:00
parent 968afe4fe4
commit 43885bed4f

View File

@ -195,6 +195,33 @@ $('input[name=isin]').change(function(e){
else {$('input[name=isin]').css("border-color", "");}
});
});
function cpville(inputFld, outputFld, countrySel=null, countryVal=null) {
$('input[name='+inputFld+']').autocomplete({
minLength: 4,
delay: 250,
source: function(request, response) {
var cpVille = $('input[name='+inputFld+']').val();
$.getJSON('<?=$this->url(array('controller'=>'saisie','action'=>'citysearch'),null,true)?>', { cpville: cpVille },
function(data) { response(data); }
);
},
select: function( event, ui ) {
var text = ui.item.label;
text = text.replace(ui.item.value+': ','');
if (inputFld==outputFld) {
ui.item.value = text;
}
$('input[name='+inputFld+']').attr('value', ui.item.value);
$('input[name='+outputFld+']').attr('value', text);
if (countrySel!=null && countryVal!=null){
$('select[name='+countrySel+']').val(countryVal);
}
}
})
}
cpville('adresse_cp', 'adresse_ville');
</script>
<?php } else {?>