Failing to set value of datePicker in template from variable

7 posts, 1 answers
  1. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 28 Aug 2015 Link to this post

    Hello

     

    I have a grid containing a list of work items with a detail template displaying details about each item. The detail template is a tabstrip where one tab contains the date and text for the last action taken on that work item. I'm having trouble setting the date in a datepicker.

    Here is the code for the tab: 

     

    items.Add().Text("Last action").Content(@<text>
       #var ldate=kendo.toString(lastActionDate, "yyyy-MM-dd")#
       <div class='cssLastAction'>#=ldate#
          <div>lastActionDate">@(Html.Kendo().DatePicker().Name("#=ldate#").Value("#=ldate#").ToClientTemplate())</div>
            <textarea rows="10" class="textArea" id="lastAction" name="lastAction" data-bind="value:lastAction">#= lastAction #                 </textarea>
        </div>
     </text>
      );

    I have removed some unnecessary code to keep it readable. First I take my lastActionDate from the model and format it to a string, after that I just write the result on the screen   #=ldate# to see that I get a value.

    I then also write it as name for the datepicker, again to see that i get the value when inspecting the datepicker .Name("#=ldate#")

    Last of all i also write it as the value of the datepicker .Value("#=ldate#")

    The problem is that when I inspect the datepicker it doesn't even have a value attribute.

    BUT if I instead hardcode a value .Value("1950-01-01") everything works fine.

    Why is it that ldate work in the name field but not in the value field for the datepicker and why does the hardcoded value work but the variable parsed as a string doesn't?

    Best regards

    Jonas

  2. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 28 Aug 2015 in reply to Jonas Link to this post

    Sorry, didn't find a way to edit my original post.

    there is a typo in the code section

    <div>lastActionDate">@(Html.Kendo().DatePicker().Name("#=ldate#").Value("#=ldate#").ToClientTemplate())</div>

    should be:

    <div>@(Html.Kendo().DatePicker().Name("#=ldate#").Value("#=ldate#").ToClientTemplate())</div>

    This typo is NOT in the source code so the code works except for the value of the datepicker

     

     

     

     

  3. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 01 Sep 2015 in reply to Jonas Link to this post

    Does anyone have any idea?

     

    /Jonas

  4. Answer
    Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 01 Sep 2015 Link to this post

    Hello Jonas,

    The input value will not be set because the Value method will try to convert the passed string to DateTime on the server and will fail for the template expression. You should use the HtmlAttributes method to set the value attribute:
    Html.Kendo().DatePicker().HtmlAttributes(new { value = "#=ldate#" })


    Regards,
    Daniel
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 01 Sep 2015 in reply to Daniel Link to this post

    Thank you Daniel!
  6. Bharat Saoji
    Bharat Saoji avatar
    2 posts
    Member since:
    Apr 2019

    Posted 31 Jul in reply to Daniel Link to this post

    Hi Daniels,

    I tried to use same type  code in Dot net core 2.2 version but its's failed.

    it's display blank

    Html.Kendo().DatePicker().HtmlAttributes(new { value = "#=ldate#" })

  7. Anton Mironov
    Admin
    Anton Mironov avatar
    108 posts

    Posted 03 Aug Link to this post

    Hello, Bharat,

    Nice to meet you and thank you for the question.

    I have investigated the issue and created a sample project. It appears that the value of the picker is set to the correct date. Attached to my response, the example could be found.

    Let me know if I could help you with anything else.

    Regards,
    Anton Mironov
    Progress Telerik

Back to Top