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

ColorPickerFor nullable - set default as null, change from color to null again etc

1 Answer 639 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Janusz asked on 24 May 2019, 07:58 AM

Hi! I try to use ColorPickerFor in my custom kendo grid editor popup, in this way:

<table style="width: 100%" class="detail-table detail-table-wider-first-column">
                            @(Html.Kendo().ColorPickerFor(m => m.Color).HtmlAttributes(new { data_value_primitive = "true" }).Events(e => e.Close("colorpicker_select")).ClearButton(true))


Color's type is string.

I would like to set my color in default as null (or empty string). Furthermore I would like to allow reseting previous value (some color) to null again. I added clearButton, but it was insufficient. 
I tried to add some jquery function on onClose event:

function colorpicker_select(e) {

But it wasn't worked. I thought that data_value_primitive is necessary, but it wasn't worked too.

Can I get some help?


1 Answer, 1 is accepted

Sort by
Veselin Tsvetanov
Telerik team
answered on 28 May 2019, 07:37 AM
Hello Janusz,

The Grid configuration would not accept a null value to be default for some of its field. Instead, it will default to an empty string. That empty string, however, would conflict with the ColorPicker which does not accept such value. To resolve this issue, I would suggest you to implement the following event handler for the Grid BeforeEdit() event:
.Events(e => e.BeforeEdit("onBeforeEdit"))

function onBeforeEdit(e) {
    var model = e.model;
    if (! {
        model.set('Color', null);

Attached you will find a small sample implementing the above scenario.

Veselin Tsvetanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question