Commit 840d4825 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'ps-fix-attach-a-file' into 'master'

Fix "Attach a file" not working after entering text

See merge request gitlab-org/gitlab!44216
parents 8e468417 bf3b5c7d
...@@ -6,7 +6,14 @@ import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_ ...@@ -6,7 +6,14 @@ import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_
import { disableButtonIfEmptyField } from '~/lib/utils/common_utils'; import { disableButtonIfEmptyField } from '~/lib/utils/common_utils';
export default class GLForm { export default class GLForm {
constructor(form, enableGFM = {}) { /**
* Create a GLForm
*
* @param {jQuery} form Root element of the GLForm
* @param {Object} enableGFM Which autocomplete features should be enabled?
* @param {Boolean} forceNew If true, treat the element as a **new** form even if `gfm-form` class already exists.
*/
constructor(form, enableGFM = {}, forceNew = false) {
this.form = form; this.form = form;
this.textarea = this.form.find('textarea.js-gfm-input'); this.textarea = this.form.find('textarea.js-gfm-input');
this.enableGFM = { ...defaultAutocompleteConfig, ...enableGFM }; this.enableGFM = { ...defaultAutocompleteConfig, ...enableGFM };
...@@ -22,7 +29,7 @@ export default class GLForm { ...@@ -22,7 +29,7 @@ export default class GLForm {
// Before we start, we should clean up any previous data for this form // Before we start, we should clean up any previous data for this form
this.destroy(); this.destroy();
// Set up the form // Set up the form
this.setupForm(); this.setupForm(forceNew);
this.form.data('glForm', this); this.form.data('glForm', this);
} }
...@@ -39,8 +46,8 @@ export default class GLForm { ...@@ -39,8 +46,8 @@ export default class GLForm {
this.form.data('glForm', null); this.form.data('glForm', null);
} }
setupForm() { setupForm(forceNew = false) {
const isNewForm = this.form.is(':not(.gfm-form)'); const isNewForm = this.form.is(':not(.gfm-form)') || forceNew;
this.form.removeClass('js-new-note-form'); this.form.removeClass('js-new-note-form');
if (isNewForm) { if (isNewForm) {
this.form.find('.div-dropzone').remove(); this.form.find('.div-dropzone').remove();
......
...@@ -167,7 +167,9 @@ export default { ...@@ -167,7 +167,9 @@ export default {
}, },
mounted() { mounted() {
// GLForm class handles all the toolbar buttons // GLForm class handles all the toolbar buttons
return new GLForm($(this.$refs['gl-form']), { return new GLForm(
$(this.$refs['gl-form']),
{
emojis: this.enableAutocomplete, emojis: this.enableAutocomplete,
members: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete, members: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
issues: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete, issues: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
...@@ -177,7 +179,9 @@ export default { ...@@ -177,7 +179,9 @@ export default {
labels: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete, labels: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
snippets: this.enableAutocomplete, snippets: this.enableAutocomplete,
vulnerabilities: this.enableAutocomplete, vulnerabilities: this.enableAutocomplete,
}); },
true,
);
}, },
beforeDestroy() { beforeDestroy() {
const glForm = $(this.$refs['gl-form']).data('glForm'); const glForm = $(this.$refs['gl-form']).data('glForm');
...@@ -230,7 +234,7 @@ export default { ...@@ -230,7 +234,7 @@ export default {
<div <div
ref="gl-form" ref="gl-form"
:class="{ 'gl-mt-3 gl-mb-3': addSpacingClasses }" :class="{ 'gl-mt-3 gl-mb-3': addSpacingClasses }"
class="js-vue-markdown-field md-area position-relative" class="js-vue-markdown-field md-area position-relative gfm-form"
> >
<markdown-header <markdown-header
:preview-markdown="previewMarkdown" :preview-markdown="previewMarkdown"
......
---
title: Fix attach file button not working in description fields
merge_request: 44216
author:
type: fixed
...@@ -24,7 +24,7 @@ exports[`Snippet Description Edit component rendering matches the snapshot 1`] = ...@@ -24,7 +24,7 @@ exports[`Snippet Description Edit component rendering matches the snapshot 1`] =
</div> </div>
<div <div
class="js-vue-markdown-field md-area position-relative js-expanded gfm-form" class="js-vue-markdown-field md-area position-relative gfm-form js-expanded"
> >
<markdown-header-stub <markdown-header-stub
linecontent="" linecontent=""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment