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

Placeholder Text and value field

4 Answers 1258 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chatra
Top achievements
Rank 1
Chatra asked on 25 May 2014, 09:53 PM
Hi I have States  Kendo Combox set up like below on a template ;which opens up on Grid Edit popup template.

1) For some reason even if placeholder is setup ; Combobox shows first item as Object.

2)Trying to achieve to clear the box when invalid text is entered other than in the data source.

Getstates() returns a list of states as Name and Code fields.

Template:
<tr>
     <td>
          <label for="State" class="required">State:</label>
     </td>
     <td>
          <input id="State" class="k-input k-textbox" name="State" data-bind="value:State" placeholder="State" required="required" validationMessage="State.." style="width:172px;" /> 
    
     </td>
 </tr>

Model & Field:
schema: {
      model: { State: "State",
      fields: {State: { defaultValue: { Value: "", Text: "" }, validation: { required: true} }
           }
     }
  
ComboBox:

var crudServiceBaseUrl = window.applicationBaseUrl + 'api/WebApi';
        $("#State").kendoComboBox({
                placeholder: "Select...",
                dataTextField: "Name",
                dataValueField: "Code",
                dataSource: {
                    //severFiltering: true,
                    transport: {
                        read: {
                            url: crudServiceBaseUrl + "/GetStates"
                        }
                    }
                },
                open: function (e) {
                                      valid = false;
                                  },
                select: function (e) {
                                      valid = true;
                                  },
                change: function (e) {
                                      var arrayOfStrings = $.map(this.dataSource.data(), function (val) { return val.dataTextField });
                                      if (arrayOfStrings.indexOf(this.value()) == -1) {
                                          this.value('');
                                      }
                                  },
                filter: "startswith",
                suggest: true,
                index: 0
            });

Data Array:
data: [{ Name: "Alabama, AL", Code: "AL" },{ Name: "Alaska, AK", Code: "AK" },]


4 Answers, 1 is accepted

Sort by
0
Chatra
Top achievements
Rank 1
answered on 25 May 2014, 10:00 PM
1) For some reason even if placeholder is setup ; Combobox shows first item as Object.

Please see the image attached below. missed to attach in first post
0
Georgi Krustev
Telerik team
answered on 28 May 2014, 07:39 AM
Hello Chatra,

I prepared a simple demo in my attempt to replicate the issue, but to no avail. Could you please check it and let me know if I am missing something? It will be of a great help if you can modify the demo in order to reproduce the erroneous behavior.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
William
Top achievements
Rank 1
answered on 24 Nov 2017, 11:09 AM

The place holder in this demo is not showing up. It defaults to the 1st item in the datasource "Alabama, AL".

Any idea why?

0
Ivan Danchev
Telerik team
answered on 28 Nov 2017, 08:08 AM
Hello William,

Alabama is selected because the ComboBox' index option is set in the example Georgi has linked. In order for the placeholder text to be displayed an item should not be pre-selected: dojo example (index option not configured).

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Chatra
Top achievements
Rank 1
Answers by
Chatra
Top achievements
Rank 1
Georgi Krustev
Telerik team
William
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or