diff options
Diffstat (limited to 'app/assets/javascripts/gl_form.js')
-rw-r--r-- | app/assets/javascripts/gl_form.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/app/assets/javascripts/gl_form.js b/app/assets/javascripts/gl_form.js index 0a1e5490237..6958cf4c173 100644 --- a/app/assets/javascripts/gl_form.js +++ b/app/assets/javascripts/gl_form.js @@ -6,7 +6,14 @@ import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_ import { disableButtonIfEmptyField } from '~/lib/utils/common_utils'; 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.textarea = this.form.find('textarea.js-gfm-input'); this.enableGFM = { ...defaultAutocompleteConfig, ...enableGFM }; @@ -22,7 +29,7 @@ export default class GLForm { // Before we start, we should clean up any previous data for this form this.destroy(); // Set up the form - this.setupForm(); + this.setupForm(forceNew); this.form.data('glForm', this); } @@ -39,8 +46,8 @@ export default class GLForm { this.form.data('glForm', null); } - setupForm() { - const isNewForm = this.form.is(':not(.gfm-form)'); + setupForm(forceNew = false) { + const isNewForm = this.form.is(':not(.gfm-form)') || forceNew; this.form.removeClass('js-new-note-form'); if (isNewForm) { this.form.find('.div-dropzone').remove(); |