34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
/*document.addEventListener('DOMContentLoaded', function() {
|
|
setDistance('.set-distance-js');
|
|
});
|
|
|
|
function setDistance(selector: string) {
|
|
const fields = document.querySelectorAll(selector);
|
|
if(fields) {
|
|
Array.prototype.forEach.call(fields, (field: HTMLInputElement) => {
|
|
if(field.dataset.relation){
|
|
const relatedField = <HTMLInputElement>document.getElementById(field.dataset.relation);
|
|
|
|
if(relatedField) {
|
|
field.addEventListener('input', (e) => {
|
|
e.preventDefault();
|
|
|
|
const dataList = <HTMLDataListElement>document.getElementById('destinations');
|
|
if(dataList) {
|
|
var option = Array.prototype.find.call(dataList.options, function(option) {
|
|
return option.value === field.value;
|
|
});
|
|
|
|
// Get distance
|
|
const distance = option.getAttribute('distance');
|
|
if(distance) relatedField.value = distance;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
*/
|
|
export {}
|