Declined
Last Updated: 26 Oct 2022 08:42 by ADMIN
Vladimir
Created on: 19 Oct 2022 12:45
Category: Editor
Type: Feature Request
0
Custom dropdown with ability to insert dropdown values in the text
Is it possible to create a custom dropdown that will insert a value in the text at the cursor position?

I would love to create some predefined values, and when the user selects the value from the dropdown, it will insert it in the cursor position.

This will give us the ability to define some placeholders in the text.
2 comments
ADMIN
Martin
Posted on: 26 Oct 2022 08:42

Hi Vladimir,

Thank you for the provided feedback.

Creating a custom Editor tool using the exec method and insertText command is the correct approach to achieve the desired functionality.

While the requested feature is useful in some scenarios, it is considered a custom tool that should be implemented as per project requirements due to the variety in its usage and possible configuration. Providing such a built-in tool might not cover all possible cases.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Vladimir
Posted on: 21 Oct 2022 11:09
I will post my solution here. it may help to someone. 

import {Directive, Host, Inject, Input, OnDestroy, OnInit} from '@angular/core';
import {EditorComponent} from '@progress/kendo-angular-editor';
import {ToolBarDropDownButtonComponent} from '@progress/kendo-angular-toolbar';
import {Subscription} from 'rxjs';
import {DOCUMENT} from '@angular/common';
import {EditorInserterItem} from '@core/models/editor/editor-inserter-item';

@Directive({
// tslint:disable-next-line:directive-selector
selector: 'kendo-toolbar-dropdownbutton[kendoEditorInserter][items]"'
})
export class KendoEditorInserterDirective implements OnInit, OnDestroy {
private subscriptions: Subscription = new Subscription();

@Input() items!: EditorInserterItem[];

constructor(
private dropdown: ToolBarDropDownButtonComponent,
@Inject(DOCUMENT) private document: Document,
@Host() private editor: EditorComponent
) {
}

ngOnInit(): void {
this.dropdown.textField = 'text';
this.dropdown.data = this.items;
this.subscriptions.add(
this.dropdown.itemClick.subscribe((result: any) => {
if (result?.value) {
this.editor.exec('insertText', {text: result.value});
}
})
);
}

ngOnDestroy(): void {
this.subscriptions.unsubscribe();
}
}
<kendo-toolbar-dropdownbutton text="Placeholders" kendoEditorInserter [items]="items">
</kendo-toolbar-dropdownbutton>