angulartinymce-5

focus on textarea with tinymce (tinymce-angular)


I am using tinymce with angular (tinymce-angular). The version of tinymce seems to be 5.4.1.

There are several editor fields / textareas on the page, I would like to focus on the first one on page load. Is that possible? Either in the html, or in the ts-file.

This is how I initialize the editor:

loop...

 <editor [(ngModel)]="map.get(item.id).item"
                        [ngModelOptions]="{standalone: true}"
                        (onBlur)="itemChanged(item.id)"
                        [initialValue]="map.get(item.id).item"
                        [init]="{plugins: 'link',
          menubar: false,
          toolbar:false,
          base_url: './assets/tinymce',
          suffix: '.min',
          branding: false,
          elementpath: false,
          statusbar:false,
          height:100,
          tabindex:0,
          auto_resize:true,
          placeholder: 'Type here please',
          autoresize_bottom_margin: 10}">
                </editor>

Solution

  • This kind of code seems to work:

       var currentItem = document.getElementById(divid);
                  var editors = currentItem.getElementsByTagName('iframe');
                  if (editors !== undefined && editors.length > 0) {
                    var editor = editors[0];
                    var body = editor.contentDocument.getElementsByTagName('body');
                    if (body !== undefined && body.length > 0) {
                      body[0].focus();
                    }
                  }