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

Failing to set value of datePicker in template from variable

6 Answers 883 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Jonas
Top achievements
Rank 1
Jonas asked on 28 Aug 2015, 01:00 PM

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

6 Answers, 1 is accepted

Sort by
0
Jonas
Top achievements
Rank 1
answered on 28 Aug 2015, 01:05 PM

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

 

 

 

 

0
Jonas
Top achievements
Rank 1
answered on 01 Sep 2015, 06:33 AM

Does anyone have any idea?

 

/Jonas

0
Accepted
Daniel
Telerik team
answered on 01 Sep 2015, 11:28 AM
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
0
Jonas
Top achievements
Rank 1
answered on 01 Sep 2015, 11:31 AM
Thank you Daniel!
0
n/a
Top achievements
Rank 1
answered on 31 Jul 2020, 05:11 AM

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#" })

0
Anton Mironov
Telerik team
answered on 03 Aug 2020, 06:38 PM

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

Tags
Date/Time Pickers
Asked by
Jonas
Top achievements
Rank 1
Answers by
Jonas
Top achievements
Rank 1
Daniel
Telerik team
n/a
Top achievements
Rank 1
Anton Mironov
Telerik team
Share this question
or