I am trying to make datetime picker readonly. I found the following code in the internet
$("#RequestedDate").attr('disabled', true)
.next("span.t-select")
.children("span.t-icon-calendar").css("visibility", "hidden");
which works great but it reset datetime to minimun datetime.
You want to set the "readonly" attribute, not "disabled". If it's disabled the value won't be picked up.
Related
I have a property of my model as follows:
[DisplayName("Manufactured Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateManufactured { get; set; }
In my scaffolded MVC Core view I have this code to display that value:
<input asp-for="LiftingItem.DateManufactured" class="form-control" />
In Chrome, the input shows the text "dd/mm/yyyy" and I get the error:
The specified value "09/02/2006" does not conform to the required
format, "yyyy-MM-dd".
Whereas in IE I get the actual date (e.g. "09/02/2006"). I think that difference is because Chrome is using the HTML 5 Date type input and so requires the format in "yyyy-MM-dd" format to display it?
If I remove the DisplayFormat attribute, sure enough it works in Chrome, but then in IE the date is in the wrong format ("yyyy-MM-dd" instead of "dd/mm/yyyy").
So, it seems like using DisplayFormat with a non "yyyy-MM-dd" format stops the Tag Helpers working? Is there any way to get it working nicely for both HTML 5 compatible and older browsers?
PS: I've also tried applying the formatting in the view instead using asp-format="{0:dd/MM/yyyy} as described in this question, but that also stops it working in Chrome.
Edit: I could also remove [DataType(DataType.Date)], but then I don't get the built in datepicker on HTML5 compatible browsers, which I would definitely like to on mobile devices.
Yes, you can combine the Tag Helpers with the DisplayFormat data annotation.
So, it seems like using DisplayFormat with a non "yyyy-MM-dd" format stops the Tag Helpers working? Is there any way to get it working nicely for both HTML 5 compatible and older browsers?
Just remove [DataType(DataType.Date)] from your model and the DisplayFormat(..) statement will start working as expected.
PS: I've also tried applying the formatting in the view instead using asp-format="{0:dd/MM/yyyy} as described in this question, but that also stops it working in Chrome.
You can combine the DisplayFormat(..) data annotation with the asp-format tag helper if you should require, in a specific view, a different date format than the one specified in your model.
If you have the following property in your model:
[DisplayName("Manufactured Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateManufactured { get; set; }
and a view (a Detail view for instance) with the following line of code:
#Html.DisplayFor(model => model.DateManufactured)
Then you application will display dates having a format corresponding to the one specified with the data annotation, i.e. {0:dd/MM/yyyy}. Here's an example: 23/02/2017.
If you add in another view (an Edit view for instance) the following line of code (please note that I've added a 'M' to the month format):
<input asp-for="LiftingItem.DateManufactured" asp-format="{0:dd/MMM/yyyy}" class="form-control" />
Then the asp-format will take precedence over the model's data notation and your application users could type dates like this one: 23/Feb/2017 in the input box.
The title is self explanatory. I am having difficulties setting a string value to a date time widget.
XCP has a build in function stringToDate
which i use in these examples...
1. stringToDate('5-5-2009')
2. stringToDate('05-05-2009')
3. stringToDate('5/5/2009')
But non of them work. What am I missing here ?
Also i set the value of the widget in the behaviors tab of the date widget.
If you are talking about Date-Time Input widget then you need to use dateToString not stringToDate.
I figured out the issue. It's dependent to the format in which you save your date to string value. If we save the Date-Time Input widget value in this format:
dateToString('12-12-2018', 'm-d-Y')
then doing a :
stringToDate(savedvalue) will work only when the format saved was 'm-d-Y'. It wasn't working before because i saved it as 'd-m-Y'.
In my Web Application i have changed my dijit/form/DateTextBox date format using constraints="{datePattern:'MM/dd/yyyy'}" attribute,
But when i call the form containing the dijit/form/DateTextBox using domForm.toJson the format is changed to yyyy/dd/MM
why?
How to solve it
Dijit/Form/DateTextBox is a dojo/widget not dom.
domForm.toJson access Dom's value not Dijit widget's get('value') function which gives you a formatted output as you expect.
To get correct value - Use Dijit/Form and then use form.get("value")
Dijit Form
I am trying to use Monotouch Dialog reflection API to bind to a class.
I have the following in my class:
[Entry("Birth Date")]
public DateTime BirthDate;
When this renders, it renders as a DateTime, which I suppose it expected.
Is there anyway to force this to be a date only
Thanks,
Steve
Should have read the documentation.
You can get a Date only selection by decorating the field with
[Date] instead of [Entry(....
I am using SharePoint Datetime control in one of my asp.net custom pages. The problem is that I am trying to display the value from the sharepoint field in the datetime control, but it does not display it on page load. If I refresh the page then it displays it.
<SharePoint:DateTimeControl ID="dtdueDate" DateOnly="True" runat="server" />
DateTime dateTime = Convert.ToDateTime(item["DueDate"]);
((TextBox)(dtdueDate.Controls[0])).Text = dateTime.ToShortDateString();
Any help please?
You can use dtdueDate.LocalId property for formatting date, here: MSDN and Locale IDs, Input Locales, and Language Collections for Windows XP and Windows Server 2003 or create your own DatePicker Control, read here: SharePoint DateTime Control Date Format
Good luck!
It should be
dtdueDate.SelectedDate = Convert.ToDateTime(item["DueDate"] == null ? null : item["DueDate"].ToString());