This is a migrated thread and some comments may be shown as answers.

setting value on ColorPalette

2 Answers 100 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 2
Veteran
Iron
Bob asked on 29 Jul 2019, 06:15 PM

I have a color palette declared on my form:

<kendo-colorpalette
    #riskAssessmentColourCode
    [palette]="palette"
    (valueChange)="riskAssessmentColourCodeChange($event)"
    formControlName="riskAssessmentColourCode"
    [tileSize]="30">
</kendo-colorpalette>

I declare a handle for the color palette in my component:

@ViewChild('riskAssessmentColourCode') public riskAssessmentColourCode: ColorPaletteComponent;

I try to get a handle on this to set the initial value:

this.riskAssessmentColourCode.value = this.palette[this.lastHistory.riskAssessment.riskAssessmentColourCode];

But the component is undefined and I am unable to set the value.

I can change the form control value with:

this.ncDocumentEditForm.controls['riskAssessmentColourCode'].setValue(this.lastHistory.riskAssessment.riskAssessmentColourCode);

 

But the visible component does not set in the same way as if I select it with a mouse (i.e. the selected block is not highlighted).
The design of this forum really is a joke with popup windows appearing below headers and the user unable to exit a code block if s/he hasn't inserted a line break to jump to first.  It's a very poor user experience and, if it were advertising your components as a window no-one would select your product.  Please sort it out.
How do I set the color palette value?

 

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Elena
Telerik team
answered on 31 Jul 2019, 10:33 AM
Hi Bob,

Thank you for the provided feedback.

I have prepared a StackBlitz example which demonstrates the usage of the ColorPalette component within a reactive form.

In ngOnInit() method the initial selected color value of the palette is set by using the form: FormGroup element. The form element collects a FormControl color element which is attached with FormControlName="color" to the ColorPalette. I have implemented a cutom method called selectColor() which selects random color of the listed in the palette property. Every time the `Set Random Color` button is clicked the value is updated and the new one is selected. I could not reproduce the case where the selected color tile is not highlighted.

I hope this helps.

Please, let me know if I am missing something or if you need any further assistance.

Regards,
Elena
Progress Telerik
Get quickly onboarded and successful with your Telerik and Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Bob
Top achievements
Rank 2
Veteran
Iron
answered on 31 Jul 2019, 04:42 PM

Hi Elena,

Thanks very much for replying.  I was probably a little too quick off the mark to be posting and issue.  After a while of tearing my hair out trying to set the component value I found the alternative which was to set the value of the form control as you so brilliantly demonstrated in your stackblitz example.  Sorry if I wasted your time but I'm sure it will be sueful for others asking the same question.

Cheers,
Bob

Tags
General Discussions
Asked by
Bob
Top achievements
Rank 2
Veteran
Iron
Answers by
Elena
Telerik team
Bob
Top achievements
Rank 2
Veteran
Iron
Share this question
or