DropDownList not validating

5 posts, 0 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 25 Feb 2015 Link to this post

    Hi,

    I have a dropdownlist defined as follows:
    <input class="input-width-75"
         data-role="dropdownlist" data-auto-bind="false" name="signature" data-option-label="select signature" data-value-primitive="true"
         data-text-field="name" data-value-field="name" data-bind="source: signatureDatasource, value: signature" required/>

    After running the .validate() function, tooltip not showing saying that this is required!  The required attribute is showing on the "hidden" input though in HTML.

    Any idea? 
  2. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 25 Feb 2015 in reply to Bilal Link to this post

    I did a small change by making data-text-field and data-value-field different, it works and I can see the Required message beside the dropdownlist.


    When both are equal, this means, the data-option-label record will have both the data-text-field and data-value-field same value as data-option-label, however, then they are different, data-option-label record will have data-value-field empty or null, correct? That's the only explanation I could come up with.

    How can I make it work while having both data-text-field and data-value-field the same data field?


    Thanks


  3. Kendo UI is VS 2017 Ready
  4. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 25 Feb 2015 in reply to Bilal Link to this post

    I did a small change on the above DropDownList. I made sure data-text-field and data-value-field are different, then it works.

    The only reasoning I could think of is as follows:
    - data-text-field and data-value-field refer to the same data field
    - data-value-primitive = "true"
    - data-option-label is set, means, data-text-field and data-value-field for the "data-option-label" are the same both are "select signature"

    Therefore, the value of first item selected (data-option-label) have both text and value field to be "select signature".

    If the data-text-field and data-value-field are to be different, something as "name" and "signatureId" and data-value-primitive = "false", then, data-option-label will have for text field "select signature" and for value field empty. That's why, having text and value field different + data-primitive-value = "false" makes the validation work.

    Is there any other explanation?

    Thanks

  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 27 Feb 2015 Link to this post

    Hello Bilal,

    Your observations are correct. The DropDownList creates a fake object (optionLabel) based on the dataTextField and dataValueField options. If both options are equal, then the optionLabel text will become a value. This is the as defining a SELECT element with options that does not have specific value attribute:
    <select>
      <option>Please select...</option>
      <option>Item1</option>
      <option>Item2</option>
    </select>
    The value of the first option will be the text. This exactly happens in DropDownList widget.
    If you would like to use optionLabel functionality, then you will need to use more complex objects or you will need to check whether the selected value is the optionLabel text and perform your specific business requirements.

    The valuePrimitive option is not related to this functionality.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 27 Feb 2015 in reply to Georgi Krustev Link to this post

    Hello Georgi,
    Thanks a lot. As i mentioned, I solved it by using an object for the value selected, and hence it works now. 

    Best regards
    Bilal Haidar
Back to Top
Kendo UI is VS 2017 Ready