WTextEdit - can't pass certain configuration options
Added by Mark Travis 5 days ago
I need a way to get TinyMCE to change it's color scheme from light to dark to mimic what a user sets in bootstrap 5.
In the initialization of the Wt::WTextEdit object, I specified the following:
std::string skinString = "useDarkMode ? 'oxide-dark' : 'oxide'";
setConfigurationSetting("skin", Wt::cpp17::any(skinString));
Unfortunately, Wt translated that to the following javascript in tinyMCE.init:
skin: 'useDarkMode ? \'oxide-dark\' : \'oxide\'',
The logic part for "skin:" has tick marks at the beginning and end, which is preventing that from working. Is there a way to force Wt to not use the tick marks for options? Perhaps set an unsafeXHTML flag or something?
Replies (1)
RE: WTextEdit - can't pass certain configuration options - Added by Romain Mardulyn 2 days ago
Hi Mark,
The function setConfigurationSetting() is not designed to execute arbitrary JavaScript code. If the second parameter is a string, it will be interpreted as a literal string within the generated JavaScript configuration.
I would recommend that, instead, you make your WApplication aware of whether dark mode is active or not. If this dark mode detection is being performed in JavaScript, you can use a JSignal to notify the WApplication when the mode is initially set or when it changes.
If you really need to implement this using setConfigurationSetting(), it is possible by embedding the complete conditional expression within the setting name, like this:
setConfigurationSetting("skin:useDarkMode ? 'oxide-dark' : 'oxide',dummy", Wt::cpp17::any(""));
This is however a hack, so there is no guaranties that it will continue to work in future versions.