scinote-web/app/assets/javascripts/shared/replace_form.js

25 lines
596 B
JavaScript
Raw Normal View History

2021-04-30 19:26:06 +08:00
(function() {
'use strict';
function initReplaceFormListeners() {
2021-04-30 19:26:06 +08:00
$(document).on('ajax:success', 'form[data-action*="replace-form"]', function(_, { form, flash }) {
let newForm = $(form);
let target = this.getAttribute('data-target');
if (target) {
$(target).replaceWith(newForm);
} else {
$(this).replaceWith(newForm);
}
2021-04-30 19:26:06 +08:00
newForm.find('.selectpicker').selectpicker();
2021-04-30 19:26:06 +08:00
if (flash) {
HelperModule.flashAlertMsg(flash, 'success');
}
});
}
$(document).one('turbolinks:load', initReplaceFormListeners);
})();