Skip to content

disabling formgroup with tinymce in material tab gives 'node cannot be null or undefined' bug. #167

Description

@airasyaqub

What is the current behavior?
I am using my tinymce editor with form-group reactive forms. As per the standard functional flow in my component there is a global Redux state for progress bar with boolean value which gets set in HTTP interceptor accordingly. I subscribe to it and disable the form group when progress bar (means API call is in progress) is true and enable it when set to false. This piece of functionality have created subtle multiple bugs in my component. Getting 'node cannot be null or undefined' error, form-group with tinymce getting dirty automatically when changing tab, other form fields in form-group also not getting disabled in UI.

What is the expected behavior?

Expected behavior was to disable a whole formgroup without any repercussions.

Which versions of TinyMCE/TinyMCE-Angular, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or TinyMCE-Angular?

I am using version "@tinymce/tinymce-angular": "^3.5.0" and "tinymce": "^5.2.0"

below is my code:

<editor formControlName="inputEditor" [init]="defaultConfig"></editor>

private _disableFormsDuringProgress() { this.progressBar$.subscribe(res => { if (res) { this.emailForm.disable(); } else { this.emailForm.enable(); } }); }

public defaultConfig: any = { height: 700, base_url: '/tinymce', // Root for resources suffix: '.min', plugins: [ 'advlist autolink link image lists charmap print hr anchor pagebreak', 'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking', 'table emoticons template paste help' ], browser_spellcheck: true, toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify |' + ' bullist numlist outdent indent | link image | print media fullpage | ' + 'forecolor backcolor emoticons | help', menubar: 'file edit view insert format tools table help', branding: false, setup: (editor: any) => { this.editor = editor; this.editor.on('init', () => { this.editorLoaded = true; }); } };

Activity

  1. airasyaqub commented on Jun 2, 2020

    @airasyaqub
    Author

    core.js:15724 ERROR Error: Node cannot be null or undefined at Object.ot [as fromDom] (tinymce.min.js:9) at cE (tinymce.min.js:9) at mE (tinymce.min.js:9) at tinymce.min.js:9 at FE.set [as setMode] (tinymce.min.js:9) at EditorComponent.push../node_modules/@tinymce/tinymce-angular/fesm5/tinymce-tinymce-angular.js.EditorComponent.setDisabledState (tinymce-tinymce-angular.js:559) at forms.js:2062 at forms.js:2831 at Array.forEach (<anonymous>) at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.disable (forms.js:2831)

    this is the exception I get every time and seems to be primary reason for all the above bugs. Due to this the else code block in _disableFormsDuringProgress() doesn't run hence not enabling the form again. Sometimes the values are also not stored correctly in payload as the form is disabled. It makes the data corrupted which causes further bugs as form getting dirty automatically. I tried to initialize the tinymce config in component too rather then in html to have kind of full control in a single place but then it gives pah error as 'tinymce/silves/theme.js' cant found. I think docs should also be updated regarding it.

    @jscasca kindly can u please help me out with it.

  2. jscasca commented on Jun 3, 2020

    @jscasca
    Contributor

    Hi @airasyaqub

    I don't think I'm following correctly on the issue. So the problem is not disabling the component but changing tabs?

    Could you provide a small replication case to better understand the issue? I don't see any issues with your editor configuration and enabling/disabling the editor as a form component seems to be working normally. If you can create one replication case in a code sandbox I could take a look into it.

  3. airasyaqub commented on Jun 3, 2020

    @airasyaqub
    Author

    https://codesandbox.io/s/elastic-poitras-j8vu2, To reproduce change the tab at least once and click the button u will note the error . Well I am pretty sure what the problem is. Changing tab destroys the editor instance. If we re enter the tab with editor the init event generates again with new editor ID which means new editor instance. so when forms get disable, the model form control is bonded with destroyed instance of editor due to which throws error of 'node cannot be null or undefined'. @jscasca

  4. changed the title [-]disabling formgroup with tinymce in it creates multiple bugs[/-] [+]disabling formgroup with tinymce in material tab gives 'node cannot be null or undefined' bug.[/+] on Jun 3, 2020
  5. airasyaqub commented on Jun 12, 2020

    @airasyaqub
    Author

    @jscasca have u looked into it ?

  6. jscasca commented on Jun 24, 2020

    @jscasca
    Contributor

    We are still working on how to fix this issue. Sorry it's taking so long

  7. nischi commented on Sep 9, 2020

    @nischi

    Any update or workaround?

  8. airasyaqub commented on Sep 9, 2020

    @airasyaqub
    Author

    @nischi the workaround I have implemented is to separate template and TS code and then manually update form control values with help of editor built in events. Here is the code

    template

    <div [hidden]="editorLoaded === false">
    	<editor [disabled]="(progressBar$ | async)" [init]="defaultConfig"></editor>
    	<mat-error *ngIf="emailForm.controls.inputEditor.invalid">
    		Please enter email body without any script tag.
    	</mat-error>
    </div>
    

    TS code

    	public defaultConfig: any = {
    		height: 700,
    		base_url: '/tinymce', // Root for resources
    		suffix: '.min',
    		plugins: [
    			'advlist autolink link image lists charmap print hr anchor pagebreak',
    			'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
    			'table emoticons template paste help'
    		],
    		browser_spellcheck: true,
    		toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify |' +
    			' bullist numlist outdent indent | link image | print media fullpage | ' +
    			'forecolor backcolor emoticons | help',
    		menubar: 'file edit view insert format tools table help',
    		branding: false,
    		setup: (editor: any) => {
    			this.logService.debug('editor ===>', editor);
    			this.editor = editor;
    			editor.on('init', () => {
    				this.editorLoaded = true;
    				this.editor.setContent(this.emailForm.get('inputEditor').value);
    			});
    
    			// Change removed
    			editor.on('Paste input Undo Redo keyup', function (e) {
    				this.emailForm.get('inputEditor').setValue(this.editor.getContent());
    				this.emailForm.get('inputEditor').updateValueAndValidity();
    				this.emailForm.get('inputEditor').markAsDirty();
    			}.bind(this));
    		}
    	};
    
  9. nischi commented on Sep 9, 2020

    @nischi

    @airasyaqub awesome, thanks a lot for the code

  10. bassemnaffeti commented on Sep 21, 2023

    @bassemnaffeti

    Hello I am using "@tinymce/tinymce-angular": "^7.0.0" and I have this issue too,
    ERROR Error: Uncaught (in promise): Error: Node cannot be null or undefined

  11. TinyITAdmin commented on Sep 21, 2023

    @TinyITAdmin

    Ref: INT-3231

  12. tiny-ben-tran commented on Mar 17, 2026

    @tiny-ben-tran
    Contributor

    @airasyaqub, @bassemnaffeti, it appears that the issue is fixed when updated @tinymce/tinymce-angular and angular to 7 and 15 respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions