0

Never seen this issue before, very strange! Basically I have a simple datepicker:

<input data-val="true" data-val-required="The StartDate field is required." id="StartDate" name="StartDate" readonly="True" type="text" value="12/12/2013 00:00:00" />

<script>
$("#StartDate").datepicker({ dateFormat: 'yy-mm-dd' });
</script>

But when I pick a date, it appears in the text box in the format '2013-12-dd'. Anybody seen this problem before?

EDIT

Here is the code that is generating the html input element:

@Html.TextBoxFor(x => x.StartDate, new {@readonly=true})
Owain Reed
  • 333
  • 1
  • 4
  • 17
  • 1
    Why are you giving value in different format like `value="12/12/2013 00:00:00"`? (Not sure if that matters or not, though.) – MysticMagicϡ Dec 12 '13 at 13:31
  • That's asp.net inserting a raw datetime. Possibly the problem? i was going to change afterwards but I'll change it now and see if it makes a difference. – Owain Reed Dec 12 '13 at 13:33
  • Try putting `type="date"` instead of text. And check if you are facing [this](http://stackoverflow.com/a/12865237/1777090) issue – MysticMagicϡ Dec 12 '13 at 13:44
  • That completely broke it :( – Owain Reed Dec 12 '13 at 13:46
  • @EllyReed Remove the dateformat in datepicker. Just leave `$("#StartDate").datepicker();`. Let see whats happens in you envir and then try to figure out. – Praveen Dec 12 '13 at 13:50
  • Thanks Praveen - I have removed and now it's showing '12/dd/2013' – Owain Reed Dec 12 '13 at 13:51
  • @EllyReed seems weird. Is value is generated by other code? means generating date dynamically? if possible share the whole code. – Praveen Dec 12 '13 at 14:00

3 Answers3

0

There is no problem with your code :

The HTML :

<input type="text" id="StartDate" value="2013-12-12" />

The Javascript :

$("#StartDate").datepicker({ dateFormat: 'yy-mm-dd' });

Here is a jsFiddle.

kmas
  • 6,401
  • 13
  • 40
  • 62
0

Here is jsfiddle of your code. In the text box all is fine.

Alex
  • 11,115
  • 12
  • 51
  • 64
0

Ok, updating jquery ui to 1.10.3 fixed it.

I was previously using a combination of jquery 1.7.1 and jquery ui 1.8.11.

Owain Reed
  • 333
  • 1
  • 4
  • 17