tinymce-angular icon indicating copy to clipboard operation
tinymce-angular copied to clipboard

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

Open airasyaqub opened this issue 5 years ago • 10 comments

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; }); } };

airasyaqub avatar Jun 01 '20 10:06 airasyaqub

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.

airasyaqub avatar Jun 02 '20 10:06 airasyaqub

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.

jscasca avatar Jun 03 '20 04:06 jscasca

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

airasyaqub avatar Jun 03 '20 09:06 airasyaqub

@jscasca have u looked into it ?

airasyaqub avatar Jun 12 '20 09:06 airasyaqub

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

jscasca avatar Jun 24 '20 08:06 jscasca

Any update or workaround?

nischi avatar Sep 09 '20 07:09 nischi

@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));
		}
	};

airasyaqub avatar Sep 09 '20 13:09 airasyaqub

@airasyaqub awesome, thanks a lot for the code

nischi avatar Sep 09 '20 13:09 nischi

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

bassemnaffeti avatar Sep 21 '23 22:09 bassemnaffeti

Ref: INT-3231

TinyITAdmin avatar Sep 21 '23 22:09 TinyITAdmin