Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
airasyaqub opened this issue Jun 1, 2020 · 10 comments

Comments

@airasyaqub
Copy link

airasyaqub commented Jun 1, 2020

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
Copy link
Author

airasyaqub commented Jun 2, 2020

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.

@jscasca
Copy link
Contributor

jscasca commented Jun 3, 2020

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.

@airasyaqub
Copy link
Author

airasyaqub commented Jun 3, 2020

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 airasyaqub 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. Jun 3, 2020
@airasyaqub
Copy link
Author

@jscasca have u looked into it ?

@jscasca
Copy link
Contributor

jscasca commented Jun 24, 2020

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

@nischi
Copy link

nischi commented Sep 9, 2020

Any update or workaround?

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

@nischi
Copy link

nischi commented Sep 9, 2020

@airasyaqub awesome, thanks a lot for the code

@bassemnaffeti
Copy link

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

Copy link

Ref: INT-3231

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

No branches or pull requests

5 participants