Ebcosio / CLT_News

0 stars 0 forks source link

JS error when adding two-column event newsletter block #10

Closed john-hix closed 3 years ago

john-hix commented 3 years ago

Error when adding two-column event newsletter block to a template:

Uncaught TypeError: Cannot read property 'value' of null
    at Function.fromTextArea (codemirror.js:9552)
    at HTMLDocument.<anonymous> (<anonymous>:4:37)
    at e (load-scripts.php?c=0&load[chunk_0]=jquery-core,jquery-migrate,utils,moxiejs,plupload&ver=5.6:2)
    at t (load-scripts.php?c=0&load[chunk_0]=jquery-core,jquery-migrate,utils,moxiejs,plupload&ver=5.6:2)
fromTextArea @ codemirror.js:9552
.
.
.
john-hix commented 3 years ago

Found here. Running document.getElementById("options-html") in the console doesn't bring any element up, neither when editing the two-column block nor when in the main block selection screen.

How it works

Details of the diagnosis, with documentation of how the Newsletter Plugin blocks work, for reference.

The Newsletter Plugin creates inputs with ids like options-{​your-value}​ in response to calls to $controls->text('your-value') (examples here, here).

I noticed that the salutation-text block doesn't give an error, and it also has the code looking for #options-html. That's because line 49 of the salutation-text options.php file creates a input with the id options-html.

Because the two-column block's options.php file creates no input for 'html', the code at line 24 (as above) does not find any element, so it throws an error from the CodeMirror library when it tries to use the null value returned from document.getElementById().

john-hix commented 3 years ago

@Ebcosio , is there need for the CodeMirror editor in the two-column-event block? I saw you used it for some standard HTML markup for the salutation block. It seems like the presence of the JS code (causing the error) in the two-column block is a copy-paste error, and so it can be deleted. Correct me if I'm wrong.

Thanks