Telerik Forums
Kendo UI for Angular Forum
1 answer
574 views

I am trying to create a custom component that wraps the Kendo Editor so I can display a label and validation messages all within the same component. The goal is to make it reuseable and self-contained. The majority of it is working except for clearing out the form. When reset is called on the parent form (and then the form control) the backing value is reset to null but the display value remains the same. 

The code for the custom component is below. I feel like either I'm missing something or the implementation is not correct. Thanks in advance.

rich-text.component.ts

import { Component, forwardRef, Injector, Input, OnDestroy, OnInit } from '@angular/core';
import { ControlValueAccessor, FormControl, FormControlDirective, FormControlName, FormGroupDirective, NgControl, NgModel, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validator, Validators } from '@angular/forms';
import { PaletteSettings } from '@progress/kendo-angular-inputs';
import { ERROR_MESSAGES } from 'core/constants';
import { noWhitespaceValidator } from 'core/helpers/customValidators';
import { HTMLUtilities } from 'core/services/utility/html-utilities.service';
import { Subscription } from 'rxjs';

@Component({
    selector: 'rich-text',
    templateUrl: './rich-text.component.html',
    styleUrls: ['./rich-text.component.scss'],
    providers: [
        {
          provide: NG_VALUE_ACCESSOR,
          multi: true,
          useExisting: forwardRef(() => RichTextComponent)
        },
        {
            provide: NG_VALIDATORS,
            useExisting: forwardRef(() => RichTextComponent),
            multi: true
          }      
      ]
  })
  
export class RichTextComponent implements OnInit, OnDestroy, ControlValueAccessor, Validator {

    @Input() label: string = 'Please supply label';
    @Input() placeholder: string = 'Please provide a value';

    public paletteSettings: PaletteSettings = {
        palette: 'basic'
    }

    formControl = new FormControl('', [Validators.required, noWhitespaceValidator]);
    subs: Subscription[] = [];
    _htmlUtilities: HTMLUtilities;
    onChange: any = () => {};
    onTouch: any = () => {};

    constructor(htmlUtilities: HTMLUtilities) {
        this._htmlUtilities = htmlUtilities;
    }

    ngOnInit(): void {

    }

    ngOnDestroy(): void {
        this.subs.forEach((s) => s.unsubscribe());
    }

    writeValue(value: string): void {
        if (value) {
            this.formControl.setValue(value);
        }

        if (value === null) {
            this.formControl.reset();
            this.formControl.setValue('');
        }
    }

    registerOnChange(fn: any): void {
        this.subs.push(
            this.formControl.valueChanges.subscribe(fn)
          );
    }

    registerOnTouched(fn: any): void {
        this.onTouch = fn;
    }

    validate(_: FormControl) {
        return this.formControl.valid ? null : this.formControl.errors;
    }

    getErrorMessage() {
        if (this.formControl.errors['required']) {
            return ERROR_MESSAGES.REQUIRED;
        }
        if (this.formControl.errors['whitespace']) {
            return ERROR_MESSAGES.WHITESPACE;
        }
    }
}

rich-text.component.html


<div>
  <kendo-label [text]="label" class="rich-text-label"></kendo-label>
    <kendo-editor [formControl]="formControl" (blur)="onTouch()"
      [placeholder]="placeholder" [pasteCleanupSettings]="_htmlUtilities.pasteCleanupSettings">
        <kendo-toolbar>
          <kendo-toolbar-buttongroup>
            <kendo-toolbar-button kendoEditorBoldButton></kendo-toolbar-button>
            <kendo-toolbar-button kendoEditorItalicButton></kendo-toolbar-button>
            <kendo-toolbar-button kendoEditorUnderlineButton></kendo-toolbar-button>
          </kendo-toolbar-buttongroup>
          <kendo-toolbar-colorpicker
            kendoEditorForeColor
            [paletteSettings]="paletteSettings"
          ></kendo-toolbar-colorpicker>
          <kendo-toolbar-colorpicker
            kendoEditorBackColor
            [paletteSettings]="paletteSettings"
          ></kendo-toolbar-colorpicker>
          <kendo-toolbar-buttongroup>
            <kendo-toolbar-button
              kendoEditorInsertUnorderedListButton
            ></kendo-toolbar-button>
            <kendo-toolbar-button
              kendoEditorInsertOrderedListButton
            ></kendo-toolbar-button>
          </kendo-toolbar-buttongroup>
          <kendo-toolbar-buttongroup>
            <kendo-toolbar-button
              kendoEditorCreateLinkButton
            ></kendo-toolbar-button>
            <kendo-toolbar-button kendoEditorUnlinkButton></kendo-toolbar-button>
          </kendo-toolbar-buttongroup>
        </kendo-toolbar>
      </kendo-editor>
  <mat-error *ngIf="formControl.invalid">
    {{getErrorMessage(formControl) | translate}}
  </mat-error>
</div>

Martin Bechev
Telerik team
 answered on 13 Nov 2023
0 answers
591 views

The drawer is working fine when I click to select items, but there are cases where I want to select an item programmatically instead of a mouse click.

My drawer's items come from an array of DrawerItem objects:

[items]="drawerItems"

 

In the .ts file, I've tried both of these ways to change the selected item:

drawerItems[index].selected = true;
and creating a reference to the drawer with @ViewChild
drawer.items[index].selected = true;

I can see from console.log statements that both are adding a "selected = true" property to the correct DrawerItem, but it has no effect in the template.  Is there a better way to achieve this?

Software
Top achievements
Rank 1
Iron
 asked on 10 Nov 2023
1 answer
306 views

Hi,

Master Detail Grid with custom icon (expand and collapse) and align detail row columns with parent columns width in percentage. Like below image

 

 

Tsvetelina
Telerik team
 answered on 10 Nov 2023
1 answer
171 views

The colors for the taskbar overall and completed are too close to one another such that some of the user cannot tell the percent complete. Can anyone tell me the styles to use to color of the overall bar and completed portion.

I have tried (with primary colors as a test.

div.k-task-template {
    background-color: red !important;

}
k-task.k-task-complete {
    background-color: yellow !important;
}

any help would be appreciated.

Ivo
Telerik team
 answered on 10 Nov 2023
1 answer
397 views

Hi folks,

the question is: how I can modify the style of the select row checkbox inside kendo-grid?

I use the kendo-grid for AngularUI.

I have added the kendo-grid-checkbox-column for selecting multiple row. Using the <ng-template kendoGridHeaderTemplate> I'm able to change the style of the header check box.

I need to change the style of the row checkbox. I have tried to verride the css class (using <style> on the component html or adding class to the component css) .k-checkbox

new class:
.k-checkbox {
    border: 1px solid #474747 !important; 
    width:24px !important; 
    height: 24px !important;
    border-radius: 8px !important;
  }

Picture:

Yanmario
Telerik team
 answered on 10 Nov 2023
1 answer
345 views

Since upgrading to 14.0.1, if a date-picker is provided with a Date object that contains time (e.g., if I default it to "right now", aka `new Date()`), trying to change the value with the keyboard will only allow 2 digits.

So, effectively, as I try to type, say, 2013, the date-picker's year field will show:

0002
0020
0001
0013

I have not been able to find anything in the API that switches how many years the input should accept (only which year should be the "break around" for 2-digit years).

If the field is prefilled with a Date object with no time (i.e. time is 00:00:00), this doesn't happen.

What am I missing?

Tsvetelina
Telerik team
 answered on 09 Nov 2023
0 answers
292 views
I am having an issue applying a white-space: nowrap style to a kendo-textarea.  The parent kendo-textarea has the nowrap style, the textarea inside the kendo-textarea inherites the nowrap but the user agent stylesheet then overrides the nowrap and giving it a pre-wrap.

Is there a way to add styling to a textarea directly without it being inherited through kendo-textarea?
Scott
Top achievements
Rank 1
 asked on 08 Nov 2023
1 answer
99 views

Hi -

I would like to add a maximize and close buttons to my kendo-toolbar (I don't want to use kendo-window)

How can I do this?

Thanks

Yanmario
Telerik team
 answered on 08 Nov 2023
0 answers
108 views

I need to implement a multiselect functionality using mousedown with the CTRL key. Is it possible?

Thanks

Mark
Top achievements
Rank 1
Veteran
Iron
 asked on 07 Nov 2023
1 answer
623 views

Hi, I've got a button that toggles a boolean property when clicked. The button has a tooltip that appears on hover, and the tooltip text is set conditionally based on if the property is true or false.

The issue I'm having is that if the button is clicked, the tooltip only changes once you hover outside the button and then hover back over it, it does not change when the button is clicked if the cursor stays hovering on the button.

Is it possible to have the tooltip text change when the button is clicked, if the cursor stays on the button?

app.component.html:

<button
  (click)="toggleProp()"
  kendoTooltip
  [title]="prop ? 'text when prop is true' : 'text when prop is false'"
>
  test
</button>

app.component.ts:

export class AppComponent {
  prop = false;

  toggleProp() {
    this.prop = !this.prop;
  }
}

Demo: https://stackblitz.com/edit/angular-goykum-okj6jk?file=app%2Fapp.component.html

Tim
Top achievements
Rank 1
Iron
 answered on 07 Nov 2023
Narrow your results
Selected tags
Tags
+? more
Top users last month
Top achievements
Rank 1
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ivory
Top achievements
Rank 1
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
YF
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Top achievements
Rank 1
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ivory
Top achievements
Rank 1
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
YF
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?