1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| "use strict";
const
inclForm = window.document.querySelector('.displCard'),
fields = window.document.querySelectorAll('.displCard [readonly]'),
country = window.document.querySelector('.displCard #country');
function handleOnDblClick() {
if ( this.name == 'pays' ) {
country.innerHTML = fromPHPtoJS.lstCountries;
}
this.removeAttribute('readonly');
this.select();
}
function handleOnBlur() {
this.setAttribute('readonly', 'readonly');
inclForm.action = 'editField.php?field='+this.name;
inclForm.submit();
}
function handleKeyDown(e) {
if ( e.keyCode == 8 && this.hasAttribute('readonly') ) { e.preventDefault(); }
}
// Le dernier caractère saisi ou supprimé avant la touche 'enter' n'est pas pris en compte
function handleKeyPress(e) {
if ( e.keyCode == 13 && this.type != 'textarea' ) { inclForm.submit(); }
}
function listOnDblClick(e) {
this.innerHTML = fromPHPtoJS.lstCountries; // Contient la liste d'options complète
}
function listOnBlur() {
console.log(fields[2]);
alert('listOnBlur');
fields[2].value = this.firstChild.selectedIndex;
this.innerHTML = fields[2];
inclForm.preventDefault(); // Pour mise au point
//inclForm.submit(); // En attente de mise au point
}
country.ondblclick = listOnDblClick;
country.onblur = listOnBlur;
for (let i=0, max=fields.length; i<max; i++) {
fields[i].ondblclick = handleOnDblClick;
if ( i != 2 ) { fields[i].onblur = handleOnBlur; }
fields[i].onkeydown = handleKeyDown;
fields[i].onkeypress = handleKeyPress;
} |