fix sources block not updating properly after saving (#216)

This commit is contained in:
mdashlw 2024-03-24 18:44:48 +03:00 committed by GitHub
parent 921ad0c59a
commit 1f440475ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 4 deletions

View file

@ -11,8 +11,7 @@ function formResult({target, detail}) {
const elements = {
'#description-form': '.image-description',
'#uploader-form': '.image_uploader',
'#source-form': '#image-source'
'#uploader-form': '.image_uploader'
};
function showResult(resultEl, formEl, response) {

View file

@ -1,6 +1,6 @@
import { inputDuplicatorCreator } from './input-duplicator';
function imageSourcesCreator() {
function setupInputs() {
inputDuplicatorCreator({
addButtonSelector: '.js-image-add-source',
fieldSelector: '.js-image-source',
@ -9,4 +9,18 @@ function imageSourcesCreator() {
});
}
function imageSourcesCreator() {
setupInputs();
document.addEventListener('fetchcomplete', ({ target, detail }) => {
const sourceSauce = document.querySelector('.js-sourcesauce');
if (target.matches('#source-form')) {
detail.text().then(text => {
sourceSauce.outerHTML = text;
setupInputs();
});
}
});
}
export { imageSourcesCreator };

View file

@ -1,4 +1,4 @@
.block
.js-sourcesauce
- has_sources = Enum.any?(@image.sources)
= form_for @changeset, Routes.image_source_path(@conn, :update, @image), [method: "put", class: "hidden", id: "source-form", data: [remote: "true"]], fn f ->
= if can?(@conn, :edit_metadata, @image) and !@conn.assigns.current_ban do