Aangepaste velden worden niet ingevoegd met de nieuwe ProseMirror editor

AI-generated summary

The issue concerns custom fields not being inserted in the ProseMirror editor when creating events in the Discourse Calendar plugin. manut reports that while custom fields work with the markdown editor, they are missing in the WYSIWYG ProseMirror editor. The problem arises because the EVENT_ATTRIBUTES constant in the editor extension does not include custom fields, preventing them from being converted from markdown. manut identifies the root cause and notes that the addText() method receives the correct text but the conversion fails. renato confirms that custom fields are currently unsupported in the rich editor and that the team will investigate a solution.

Hallo!

We hebben een probleem met aangepaste tags voor gebeurtenissen en de nieuwe WYSIWYG ProseMirror-editor: aangepaste velden die vanuit het gebeurtenisformulier zijn ingevuld, zijn niet aanwezig in de gegenereerde string. Het werkt nog steeds zoals voorheen met de markdown-editor.

Stappen om te reproduceren:

  1. Schakel de Discourse Calendar-plugin in
  2. Voeg één aangepast veld toe in de pluginconfiguratie
  3. Open een formulier voor een nieuwe Post
  4. Selecteer de ProseMirror-editor
  5. Maak een gebeurtenis met een waarde voor het aangepaste veld (Opties > Gebeurtenis maken)
  6. Valideer de gebeurtenis
  7. Schakel over naar de Markdown-editor

Wat er gebeurt

Het aangepaste veld ontbreekt in de [event] tag.

Wat wordt verwacht

Het aangepaste veld moet aanwezig zijn in de [event] tag.

Opmerkingen

Wanneer hetzelfde wordt gedaan, maar beginnend met de Markdown-editor in plaats van ProseMirror, is het aangepaste veld aanwezig in de [event] tag.

2 likes

Ik heb een beetje onderzocht wat er aan de hand was met de toolbarEvent bij het valideren van de nieuwe gebeurtenis: de addText() methode lijkt in beide gevallen de juiste markup te ontvangen:

[event start="2025-09-26 18:00" status="public" timezone="Europe/Paris" end="2025-09-26 19:00" cf_1="abcd"]\n[/event]

Als dat kan helpen, hier is de QUnit-test om het probleem te reproduceren:

// plugins/discourse-calendar/test/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:

I can’t find another plugin with the same feature, so it’s hard to find what’s wrong.

When validating the form, it calls this.args.model.toolbarEvent.addText() with the right text.

A few console.log™ lead me to : text-manipulation.js#addText() where this.convertFromMarkdown(text) gets called. It seems that the issue comes from here : there is a kind of schema enforced, and it does not contains the custom fields.

Still digging :shovel: …

The issue comes from the editor extension discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js : the list of attributes used by convertFromMarkdown() is defined in the EVENT_ATTRIBUTES constant. It works when adding the custom field to the list.

const EVENT_ATTRIBUTES = {
  // ...
  chatChannelId: { default: null },
  myCustomField: {default: null}
};

There is nothing about custom fields in this file; I have no idea on how to complete this constant with all the custom fields; the extension seems to get registered early in the process.

Any idea welcome, it makes the plugin unusable with the new editor that can’t be disabled, so we’re stuck with Discourse 3.4.

Custom fields are indeed unsupported on the rich editor for now. We’ll investigate the best path forward.

It can – if you’re an admin, you can set SiteSettings.rich_editor = false via the console, which is still available as a last resort in cases like this.

1 like

Thanks for your reply, we’ll disable the editor for now.

This has been fixed by FIX: restore post event allowed custom fields - Pull Request #40551 - discourse/discourse - GitHub