Makoto Posted March 25, 2019 Posted March 25, 2019 When trying to add something like the following to a form in the Wizard helper, $form->add( new \IPS\Helpers\Form\Codemirror( 'some_advancedEditor', '<strong>Hello world</strong>', TRUE, [ 'tags'=> [ '{foo}' => '', '{bar}' => '' ] ] ) ); You get this, Similarly, if you try and use TextArea with tags, the tags just don't work. Clicking on them does nothing. This only happens when trying to use the two in the Wizard helper. When using TextArea, clicking on tags logs "TypeError: textField.getSelection is not a function" in the console. In CodeMirror, nothing of interest logged in the javascript console or anything of the sort that I can see. It's just something with the Wizard helper that completely breaks it.
bfarber Posted March 25, 2019 Posted March 25, 2019 I've logged a bug report to have this checked into in a future release.
Makoto Posted March 25, 2019 Author Posted March 25, 2019 49 minutes ago, bfarber said: I've logged a bug report to have this checked into in a future release. FWIW I spent a bit trying to figure out this bug and it's the craziest thing. It's not the javascript controller for the Wizard, the issue persists even with that disabled. It's not the template. I can literally have the Wizard helper spit out the exact same output (minus the addtostack strings) and it will still break the two,https://www.diffchecker.com/AGQrdbkh (Left is broken, but the right (on a dedicated page outside the Wizard helper), for whatever reason, works) So what's left to break it? I don't know ¯\(°_o)/¯ Have fun with this one
Makoto Posted March 25, 2019 Author Posted March 25, 2019 Nevermind, I figured out the cause. @bfarber when using the Wizard helper, css files and js scripts that are set via constructors in the form helpers are not honored. So, when using CodeMirror, you're missing the following in the output, /* Append our necessary JS/CSS */ \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'codemirror/diff_match_patch.js', 'core', 'interface' ) ); \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'codemirror/codemirror.js', 'core', 'interface' ) ); \IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'codemirror/codemirror.css', 'core', 'interface' ) ); Hacking it back in resolves the issue. Probably the same for TextArea, there's a missing js library. Must have something to do with how the Wizard uses callbacks to handle output somewhere.
Daniel F Posted March 25, 2019 Posted March 25, 2019 I wish I would have seen this topic earlier, we're actually aware of this. The same applies also to upload fields! If you take a look at the downloads submit form or the commerce gateway form, you have to explicit add the pluploader files to the output object. if ( \IPS\IN_DEV ) { \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) ); \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) ); } else { \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) ); } I can't remember why, maybe @Rikki ?
Makoto Posted March 25, 2019 Author Posted March 25, 2019 1 minute ago, Daniel F said: I wish I would have seen this topic earlier, we're actually aware of this. The same applies also to upload fields! If you take a look at the downloads submit form or the commerce gateway form, you have to explicit add the pluploader files to the output object. if ( \IPS\IN_DEV ) { \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) ); \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) ); } else { \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) ); } I can't remember why, maybe @Rikki ? Another alternative is to simply cast the Wizard to a string before sending the output, but yeah. $output = (string)$wizard; \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('radtags_prefix_create'); \IPS\Output::i()->output = $output; Any javascript/css resources set inside a callback doesn't get added to the final output. The issue lies somewhere where the output is actually generated, it seems the \IPS\Output::i()->output field is cast to a string too late somewhere and it ends up missing any resources set in a __toString() method assigned there (e.g. the Wizard helper)
Makoto Posted March 25, 2019 Author Posted March 25, 2019 @Daniel F, Looks like it's because the value assigned to \IPS\Output->output is only cast to a string in the generated template output files, so all the headers and etc. will have already been defined and can't be changed. #0 IPS\Helpers\_Wizard->__toString() called at [/tmp/theme_core_admin_global_globalTemplateLUXgMh:717] So, either always cast things to a string before assigning them to the output property and don't forget this, or change the way template files are written would be your two choices. That's as far as I'm taking this though.
bfarber Posted April 4, 2019 Posted April 4, 2019 I've researched this and yes, you will need to cast your wizard as a string manually before sending it to the output library. This usually isn't an issue, but a handful of form helpers require extra resources to be loaded and they won't be loaded if the wizard isn't cast to a string before it is sent to a template (at which point it may be too late to include the necessary resources).
Recommended Posts
Archived
This topic is now archived and is closed to further replies.