0

I am using KendoDropDownList for my project and replacing the select box options from script.

I want to add css class placeholder if I select optionLable (-- Please select --)

Online Demo

Please check the below reference image what I am talking about..

enter image description here

HTML

<select id="selectBox" data-bind="value: index, source: newOptions">
  <option>{Label 1}</option>
  <option>{Label 2}</option>
  <option>{Label 3}</option>
</select>

Script

$("#selectBox").kendoDropDownList({
  valuePrimitive: true,
  dataTextField: "text",
  dataValueField: "value",
  optionLabel: "-- Please select --"
});
var icsNew = kendo.observable({
  index: 2,
  newOptions: [
    { value: 1, text: "My option 1" },
    { value: 2, text: "My option 2" },
    { value: 3, text: "My option 3" } ]
});
kendo.bind($("#selectBox"), icsNew);

CSS

.k-dropdown{border:1px solid #ccc;}
.placeholder{color:red;}
Reddy
  • 1,477
  • 29
  • 79

1 Answers1

2

You can achieve it with optionLabelTemplate:

$("#selectBox").kendoDropDownList({
    ...
    optionLabel: "-- Please select --",
    optionLabelTemplate:'<span style="color:red">-- Please select --</span>',
    ...
});
Gene R
  • 3,684
  • 2
  • 17
  • 27
  • Hi **@Gene R**, thanks for the answer.. but still not working... please check the updated demo... **http://dojo.telerik.com/AbIyI** – Reddy Jan 29 '16 at 08:19
  • @Reddy do not remove `optionLabel` – Gene R Jan 29 '16 at 08:24
  • Thanks **Gene R**... it is working as expected... but should I need to maintain placeholder in 2 places?... `optionLabel: "-- Please select --", optionLabelTemplate:'-- Please select --'` ... please correct me if I am wrong... – Reddy Jan 29 '16 at 08:36
  • @Reddy yes, but it works even if optionLabel is empty space: `optionLabel: " "` – Gene R Jan 29 '16 at 08:39
  • Thanks again.. I am accepting your answer and upvoting :) – Reddy Jan 29 '16 at 09:23