Issue encountered while trying to utilize the reset function of the FormGroup with the angular2-tinymce plugin

I utilized the FormGroup feature to construct my form, and I required a textarea component. I decided to use the angular2-tinymce library/package to create the form. Here is my HTML template:

  <form (submit)="submitCallLog($event)" [formGroup]="callLogForm">
    <label for="title">Title</label>
    <input type="text" id="title" formControlName="title">
    <div [hidden]="callLogForm.controls.title.valid">
      <p><i>Title is required</i></p>
    </div>
    <label for="content">Content</label>
    <app-tinymce id="content" formControlName="content"></app-tinymce>
    <button type="submit" class="right-align">Submit</button>
  </form>

My Class:

export class NewCallLogComponent implements OnInit {
  isNewCallLog = false;
  callLogForm: FormGroup;
  constructor(private fb: FormBuilder,
              private route: ActivatedRoute,
              private callLogService: CallLogService
  ) { }

  ngOnInit() {
    this.createForm();
    this.callLogForm.valueChanges.subscribe(values => {
      console.log('Changed: ', values);
    })
  }


  createForm () {
    this.callLogForm = this.fb.group({
      title: ['', Validators.required],
      content: ['', Validators.required]
    });

  }


  resetFormValue() {
    this.callLogForm.reset();
  }

  submitCallLog(e) {
    console.log('Event: ', e);
    e.preventDefault();
    this.isNewCallLog = false;
    const cusId = +this.route.snapshot.params['id'];
    const newCallLog = new CallLog(
      new Date().toLocaleString(),
      this.callLogForm.value.title,
      this.callLogForm.value.content,
      'anonymous'
    );
    this.callLogForm.reset();
    this.callLogService.addCallLog(cusId, newCallLog);

  }
}

Upon submitting the form, everything performs correctly except for a handling error:

ERROR TypeError: Cannot read property 'length' of null
    at o.setContent (http://localhost:4200/0.chunk.js:13388:23574)
    at TinymceComponent.webpackJsonp.452.TinymceComponent.writeValue (http://localhost:4200/0.chunk.js:659:40)
    at http://localhost:4200/vendor.bundle.js:21277:29
    at http://localhost:4200/vendor.bundle.js:22463:65
    at Array.forEach (native)
    at FormControl.setValue (http://localhost:4200/vendor.bundle.js:22463:28)
    at FormControl.reset (http://localhost:4200/vendor.bundle.js:22518:14)
    at http://localhost:4200/vendor.bundle.js:22822:21
    at http://localhost:4200/vendor.bundle.js:22861:66
    at Array.forEach (native)
View_NewCallLogComponent_0 @ NewCallLogComponent.html:5
proxyClass @ compiler.es5.js:14091
DebugContext_.logError @ core.es5.js:12981
ErrorHandler.handleError @ core.es5.js:1144
(anonymous) @ core.es5.js:9373
(anonymous) @ platform-browser.es5.js:2683
ZoneDelegate.invokeTask @ zone.js:414
onInvokeTask @ core.es5.js:4117
ZoneDelegate.invokeTask @ zone.js:413
Zone.runTask @ zone.js:181
ZoneTask.invoke @ zone.js:476
NewCallLogComponent.html:5 ERROR CONTEXT DebugContext_ {view: Object, nodeIndex: 12, nodeDef: Object, elDef: Object, elView: Object}
View_NewCallLogComponent_0 @ NewCallLogComponent.html:5
proxyClass @ compiler.es5.js:14091
DebugContext_.logError @ core.es5.js:12981
ErrorHandler.handleError @ core.es5.js:1149
(anonymous) @ core.es5.js:9373
(anonymous) @ platform-browser.es5.js:2683
ZoneDelegate.invokeTask @ zone.js:414
onInvokeTask @ core.es5.js:4117
ZoneDelegate.invokeTask @ zone.js:413
Zone.runTask @ zone.js:181
ZoneTask.invoke @ zone.js:476

This error prevents the form from being reset. Can anyone provide assistance?

Answer №1

Apologies for the delayed response, but perhaps others have faced this issue as well. I ran into a similar problem when utilizing a custom component wrapper for tinyMCE. The issue in my scenario arose when triggering a form reset, causing the ControlValueAccessor writeValue method to receive null as a parameter. I resolved the problem by implementing a basic condition to prevent setting the tinyMCE editor content to null.

Hopefully, this solution proves helpful to others!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Collision Detection within a THREE.Group in Three.js

Currently, I am tackling the challenge of detecting 3D AABB collisions between a box and a sphere. An interesting observation: when a box is directly added to the scene, collisions are detected successfully. However, when the box is added to a group (THRE ...

Incorrect types being identified

What is the reason behind the callback assuming the type string | number | boolean instead of determining the exact type based on the property passed as the first argument in the carWithListener.on function? const car = { paint: "red", ...

A property in TypeScript with a type that depends on the value of an object

How can we troubleshoot the error not displaying in Typescript and resolve it effectively? Explore Typescript sandbox. enum Animal { BIRD = 'bird', DOG = 'dog', } interface Smth<T extends Animal = Animal> { id: number; a ...

Changing MySQL Limit arguments into numerical values

I'm encountering an issue with my Rest call to a MySQL database. I'm using a JavaScript object and sending it through a REST GET call with a Java back-end. requestParams: { pageStart: 0, results: 10 } I have configured ...

Having trouble correctly displaying a form with nested form array within a form group

I am working with a form group that contains nested form groups and a form array: ngOnInit() { this.form = this.fb.group({ dropDownOptions: this.fb.group({ items: this.fb.array([this.createItem()]) }) ...

"Exploring the process of comparing dates using HTML, AngularJS, and Ionic

I am working on an HTML file that shows a list of notification messages. I am trying to figure out how to display the time difference between each notification. The code snippet below displays the notifications and includes the time for each one: <ion- ...

Database hosted on Heroku platform

Curious to know, if you utilize Heroku for hosting, what database do you prefer? Do you lean towards PostgreSql, MongoDB, or another option altogether? I initially developed a bot using sqlite3, but quickly discovered that Heroku does not support it and ...

Is there a way to incorporate the load page plugin specifically for JavaScript while ensuring that my PHP code is still functional?

Is there a way to implement the loading page plugin "PACE" for PHP code execution instead of just JavaScript? I am more comfortable with PHP, CSS, and HTML, but not very experienced in JavaScript/AJAX. The PACE plugin is designed to show a progress bar fo ...

Is there a way to divide a single array into two separate arrays based on a specific element?

My goal is to create an interactive graph using plotly.js. I have an array named data that contains all the information needed for the graph. However, I want users to be able to select specific elements to display on the graph. To achieve this functionalit ...

Unable to add personalized repository

Looking to implement a request-scoped cache for my repositories, inspired by Hibernate's first-level-cache. I have some ideas on how to achieve this and integrate it with typeorm-transactional-cls-hooked. For now, I've created a basic provider s ...

Guide to converting the title into an H2 heading

I am currently working on a page that displays a dynamic title. However, when I attempt to change the title to h2 using HeaderCfg, it wraps the text in a span tag like this: <h2 class=" x-unselectable"> <span class="x-panel-header ...

Limit the number input to only allow values between 0 and 100

I am utilizing the Number input component from MUI, which includes Increment and Decrement buttons for adjusting numbers. Is there a method to limit the input to only accept values ranging from 0 to 100 ? Additionally, how can I decrease the width of the ...

What is the process for building .ts components within a Vue application?

Looking to update an old project that currently uses the 'av-ts' plugin and vue-ts-loader to compile .ts files as Vue components. The project is running on Vue 2.4.2, but I want to upgrade it to version 2.6.14. However, since 'vue-ts-loader& ...

Utilizing JQuery UI autocomplete for dynamically loaded textbox using AJAX

<div id='toolbox'> <div class='placeholder'></div> </div> In my project, I am using a click event to dynamically load a text box into the placeholder. $('#toolbox .placeholder').load('http:// ...

What are the steps to resolve the End of Expression issue in my Directive's markup?

Issue: $parse:ueoe Unexpected End of Expression Upon inspecting Chrome's console, the following error is displayed: <div ng-class="{" green-up":="" tgh.tag.direction="=" "positive",="" "red-down":="" "negative",="" ""="" :="" "stagnant"}"=""> ...

What is the best way to retrieve specific feature properties in Open Layers 3 on-the-fly?

Within my map, I have two types: Point and Polygon, each with unique properties such as id, door number, and name. I have generated a list of features as follows: var features = new ol.format.GeoJSON().readFeatures(geojsonObject, { featureProjection: & ...

Is it possible for me to change a selector value?

Currently, I am working on an app that utilizes NGRX. I have a question regarding the store being a readonly place where direct object mutation is not allowed. However, I am unsure about the use of selectors. For example, consider the following NGRX sele ...

What is the best way to add selected values from a multi-select dropdown into an array?

Attempting to populate an array from a multiple select dropdown, I've encountered an issue. Despite using splice to set the order of values being pushed into the array, they end up in a different order based on the selection in the dropdown. For insta ...

Implementing a more efficient method for incorporating UUIDs into loggers

------------system1.ts user.on('dataReceived',function(data){ uniqueId=generateUniqueId(); system2.processData(uniqueId,data); }); ------System2.ts function processData(u ...

Using jQuery and AJAX to dynamically add data to POST parameters

Hello, I have a question that may sound like one from a newbie. I am trying to figure out how to insert a variable into a parameter for a POST request instead of simply writing the number in directly: var x = 3; id=(the var x needs to be here)&appid=4 ...