-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Input tag helper for DateTime should use "datetime-local" instead of deprecated "datetime" #4871
Comments
Neither |
That would be ok but "datetime" doesn't work on any "current" browser but "datetime-local" does. |
so? |
Triage members will decide whether to break compatibility w/ 1.0.0 and, if yes, in which release. In the meantime, does Separately, we can't choose |
fair enough. In my experience I'm using |
/cc @danroth27 |
Depends which specs you read :)
And also in the WHATWG specs: Here's the issue where Further to this, Edge, Chrome, Android and IOS Safari support UI for |
It's unfortunate we didn't see this before shipping 1.0.0. I believe it would be a breaking change to change We could in the meantime perhaps have it render as Would that be a useful change? Who would it help? Perhaps it would help pass the W3C validator? (Not sure what checks it does on this.) |
At least it won't throw warnings on browsers and those who using it will clearly see that 'it's not supported' rather than it's supported something deprecated and had to research about it. Not a huge difference, but it may help.
Not trying to be mean, I reported this at June way before RTM ships, what could I done differently? I had no confidence on showing the specs @ctolkien shown. There are so many specs that I wasn't sure if they were valid or not, that spec was available at the time of the issue was created. If there's anything I can do better when creating an issue i would really appreciate the feedback. |
@Bartmax the product was released on June 27th, just 12 days after this report. At that time the product was in escrow so we were taking only the most critical fixes (e.g. bad crashes, data loss, security issues, etc.). Unfortunately due to the timing, I don't think there was anything better anyone could have done. But anyway, I think changing it to |
@Eilon ah of course, forgot about the escrow thing. makes sense. Thanks for the feedback. In my current project, where I'm using tag helpers, I'm overriding it as In the future I will try to discover things earlier 😄 |
@Bartmax, FYI there is an overload for the [DataType("datetime-local")]
public DateTime? StartDate { get; set; } Along with the typical tag helper syntax: <input asp-for="StartDate" /> To render: <input type="datetime-local" id="StartDate" name="StartDate" value=""> You probably could write your own tag helper to come in over the top after the regular input tag helper has run to change the type. I might look at doing that in the next day or so. @Eilon I'd actually prefer this is kept as I haven't been able to repro Chrome issuing a warning against it's use (v51 or Canary), but it may be in some setting I'm unaware of. |
@ctolkien |
@Bartmax super naive implementation: //snipped crappy implementation that you should not use. See updated version below. Works on my machine, probably slow as all hell and filled with bugs, etc. etc. yadda yadda... Edit: Actually doesn't work if attribute.Value is a |
Less stringy version: [HtmlTargetElement("input", Attributes = ForAttributeName, TagStructure = TagStructure.WithoutEndTag)]
public class DateTimeTagHelper : TagHelper
{
private const string ForAttributeName = "asp-for";
//https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs#L79
//default order of the built in TagHelpers are -1000; being one higher, this will run after them.
public override int Order { get; } = -999;
[HtmlAttributeName(ForAttributeName)]
public ModelExpression For { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var modelExplorer = For.ModelExplorer;
if (!string.IsNullOrEmpty(modelExplorer.Metadata.TemplateHint) ||
!string.IsNullOrEmpty(modelExplorer.Metadata.DataTypeName))
{
return;
}
var fieldType = modelExplorer.Metadata.UnderlyingOrModelType;
if (typeof(DateTime) == fieldType)
{
output.Attributes.SetAttribute("type", "datetime-local");
}
}
} |
Moving this to 2.0.0 and marking as a breaking change. In 2.0.0 we'll change this all to be |
@Eilon it's currently |
Ah sorry, will update 😄 |
- #6648 - a different take on #4871 - `DateTime` can also round-trip `DateTimeKind.UTC` with `[DataType("datetimeoffset")]` or `[UIHint("datetimeoffset")]` - since they're now handled differently by default, add more `DateTime` tests - expand tests involving `Html5DateRenderingMode.CurrentCulture` nits: make VS-suggested changes to files updated in this PR
Fix updated in 7e4a8fe. Now use |
- cherry-picked from 7e4a8fe in dev - #6648 - a different take on #4871 - `DateTime` can also round-trip `DateTimeKind.UTC` with `[DataType("datetimeoffset")]` or `[UIHint("datetimeoffset")]` - since they're now handled differently by default, add more `DateTime` tests - expand tests involving `Html5DateRenderingMode.CurrentCulture` nits: make VS-suggested changes to files updated in this PR
- cherry-picked from 7e4a8fe in dev - #6648 - a different take on #4871 - `DateTime` can also round-trip `DateTimeKind.UTC` with `[DataType("datetimeoffset")]` or `[UIHint("datetimeoffset")]` - since they're now handled differently by default, add more `DateTime` tests - expand tests involving `Html5DateRenderingMode.CurrentCulture` nits: make VS-suggested changes to files updated in this PR
I'm not an expert, but
<input>
tag helper for model withDateTime
type renders astype="datetime"
but it look like that was deprecated in favor oftype="datetime-local"
current tag helper:
it should be:
The text was updated successfully, but these errors were encountered: