editor: insert new champs after the last fully visible champ (#4497)

Administrateur : l'éditeur de formulaire insère les nouveaux champs à l'endroit attendu
This commit is contained in:
Pierre de La Morinerie 2019-11-07 16:12:25 +01:00 committed by GitHub
commit e3382401b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,7 +56,9 @@ function addTypeDeChamp(state, typeDeChamps, insertAfter, done) {
state.flash.success();
done();
if (insertAfter) {
scrollToComponent(insertAfter.target.nextElementSibling);
scrollToComponent(insertAfter.target.nextElementSibling, {
duration: 300
});
}
})
.catch(message => state.flash.error(message));
@ -219,7 +221,7 @@ function getUpdateHandler(typeDeChamp, { queue, flash }) {
}
function findItemToInsertAfter() {
const target = getFirstTarget();
const target = getLastVisibleTypeDeChamp();
return {
target,
@ -227,8 +229,10 @@ function findItemToInsertAfter() {
};
}
function getFirstTarget() {
const [target] = document.querySelectorAll('[data-in-view]');
function getLastVisibleTypeDeChamp() {
const typeDeChamps = document.querySelectorAll('[data-in-view]');
const target = typeDeChamps[typeDeChamps.length - 1];
if (target) {
const parentTarget = target.closest('[data-repetition]');
if (parentTarget) {