Aangepaste velden worden niet ingevoegd met de nieuwe ProseMirror editor

Hello!

We have an issue with events custom tags and the new WYSIWYG ProseMirror editor: custom fields filled from the event form are not present in the generated string. It still works as before with the markdown editor.

Steps to reproduce:

  1. Enable the Discourse Calendar plugin
  2. Add one custom field in plugin configuration
  3. Open a form for a new Post
  4. Select the ProseMirror editor
  5. Create an event with a value for the custom field (Options > Create Event)
  6. Validate the event
  7. Switch to Markdown editor

What is happening

The custom field is absent from the [event] tag.

What is expected

The custom field should be present in the [event] tag.

Notes

When doing the same but starting with the Markdown editor instead of ProseMirror, the custom field is present in the [event] tag.

2 likes

I investigated a bit what was happening with the toolbarEvent when validating the new event: addText() method seems to receive in both cases the right markup:

[event start="..." status="..." timezone="..." end="..." cf_1="abcd"]\n[/event]

If that can help, here is the QUnit test to reproduce the issue:

// plugins/discourse-calendar/test/javascripts/acceptance/post-event-builder-custom-tags-test.js
import { click, find,visit, fillIn } from "@ember/test-helpers";
import { test} from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { i18n } from "discourse-i18n";

acceptance("Discourse Calendar - New event form with custom fields", function (needs) {
  needs.user({ admin: true, can_create_discourse_post_event: true });
  needs.settings({
    discourse_local_dates_enabled: true,
    calendar_enabled: true,
    discourse_post_event_enabled: true,
    discourse_post_event_allowed_on_groups: "",
    discourse_post_event_allowed_custom_fields: "my_custom_field",
    coopaname_integration_enabled: false,
  });

  test("filling the form with MD editor fills the custom fields", async function (assert) {
    await ensureEventTagHasFields(assert, 'md');
  });

  test("filling the form with WYSIWYG editor fills the custom fields", async function (assert) {
    await ensureEventTagHasFields(assert, 'wysiwyg');
  });
});

async function ensureEventTagHasFields(assert, editorType){
  await visit("/");
  await click('#create-topic');
  const categoryChooser = selectKit(".category-chooser");
  await categoryChooser.expand();
  await categoryChooser.selectRowByValue(2);

  await switchEditorTo(editorType);

  await click(".toolbar-menu__options-trigger");
  await click(`button[title='${i18n("discourse_post_event.builder_modal.attach")}']`);
  await fillIn('input.custom-field-input', 'some value')
  await click('.d-modal__footer > button');

  await switchEditorTo('md');

  const fields = ['start', 'status', 'timezone', 'myCustomField'];
  const content = await find(".d-editor-input").value;

  fields.forEach((field) => {
    assert.true(content.includes(`${field}="`), `${field} is present in event tag`);
  });
}

async function switchEditorTo(type){
  const editorSwitch = find('button.composer-toggle-switch');
  const isInMarkdown = editorSwitch.attributes['aria-checked'].value === 'false';
  if (isInMarkdown && type === 'wysiwyg' || !isInMarkdown && type === 'md') {
    await click(editorSwitch);
  }
}

Of course, remove this line in the test coopaname_integration_enabled: false, :upside_down_face: