Failing to set value of datePicker in template from variable

5 posts, 1 answers
  1. Jonas
    Jonas avatar
    39 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
    39 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. UI for ASP.NET MVC is VS 2017 Ready
  4. Jonas
    Jonas avatar
    39 posts
    Member since:
    Oct 2014

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

    Does anyone have any idea?

     

    /Jonas

  5. Answer
    Daniel
    Admin
    Daniel avatar
    2118 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
  6. Jonas
    Jonas avatar
    39 posts
    Member since:
    Oct 2014

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

    Thank you Daniel!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready