-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must also change the similar code in DefaultEditorTemplates
. Nothing is shared for reasons…
@@ -57,7 +57,7 @@ public class InputTagHelper : TagHelper | |||
new Dictionary<string, string>(StringComparer.Ordinal) | |||
{ | |||
{ "date", "{0:yyyy-MM-dd}" }, | |||
{ "datetime", "{0:yyyy-MM-ddTHH:mm:ss.fffK}" }, | |||
{ "datetime", "{0:yyyy-MM-ddTHH:mm:ss.fff}" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't change this. The bug is about the type
attribute values MVC chooses when the <input>
element has none. If users type in <input type="datetime" ... />
, we still need to use the appropriate RFC 3339 format.
@dougbu Updated |
@@ -248,7 +248,7 @@ public static TheoryData MultiAttributeCheckBoxData | |||
} | |||
|
|||
[Theory] | |||
[InlineData(null, "datetime")] | |||
[InlineData(null, "datetime-local")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a case for [InlineData("datetime", "datetime")]
i.e. demonstrate user can choose <input type="datetime">
. This might require a new test.
[InlineData("NullableDateTime", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-ddTHH:mm:ss.fffK}", "datetime")] | ||
[InlineData("NullableDateTimeOffset", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-ddTHH:mm:ss.fffK}", "datetime")] | ||
[InlineData("NullableDateTime", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-ddTHH:mm:ss.fff}", "datetime-local")] | ||
[InlineData("NullableDateTimeOffset", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-ddTHH:mm:ss.fff}", "datetime-local")] | ||
public async Task ProcessAsync_CallsGenerateTextBox_AddsExpectedAttributesForRfc3339( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the equivalent of [DataType("datetime-local")]
is now the default, add checks of a new property with an associated [DataType("datetime")]
.
@@ -350,7 +350,7 @@ public static IHtmlContent EmailAddressInputTemplate(IHtmlHelper htmlHelper) | |||
public static IHtmlContent DateTimeInputTemplate(IHtmlHelper htmlHelper) | |||
{ | |||
ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-ddTHH:mm:ss.fffK}"); | |||
return GenerateTextBox(htmlHelper, inputType: "datetime"); | |||
return GenerateTextBox(htmlHelper, inputType: "datetime-local"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks incorrect. Means users can't force generation of type="datetime"
without htmlAttributes
shenanigans. Also uses the wrong format for the chosen type
value. If this is what we wanted, would probably remove DateTimeInputTemplate()
and update this table.
In any case, won't need to change this class at all given my comments in InputTagHelper
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this... I agree that perhaps if the user typed in <input type="datetime" ... blah blah />
that we should preserve that. But I think in all other cases we should start rendering type="datetime-local"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I thought I was toeing closer to the @Eilon line. See other thread on the subject.
@@ -769,7 +769,6 @@ public void Editor_FindsViewDataMember() | |||
// DateTime-local is not special-cased unless using Html5DateRenderingMode.Rfc3339. | |||
[Theory] | |||
[InlineData("date", "{0:d}", "2000-01-02")] | |||
[InlineData("datetime", null, "2000-01-02T03:04:05.006+00:00")] | |||
[InlineData("datetime-local", null, "2000-01-02T03:04:05.006")] | |||
[InlineData("time", "{0:t}", "03:04:05.006")] | |||
public void Editor_FindsCorrectDateOrTimeTemplate(string dataTypeName, string editFormatString, string expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test covers explicit [DataType(...)]
use. Whether or not you agree [DataType("datetime")]
should work differently than [DataType("datetime-local")]
, both should be tested. I.e. these cases should remain though expectations might change.
Same for Editor_AppliesRfc3339()
and Editor_AppliesNonDefaultEditFormat()
.
@@ -32,7 +32,7 @@ public class InputTagHelper : TagHelper | |||
{ "Url", "url" }, | |||
{ "EmailAddress", "email" }, | |||
{ "Date", "date" }, | |||
{ "DateTime", "datetime" }, | |||
{ "DateTime", "datetime-local" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this more, should narrow this change to exactly what @Eilon said:
change
System.DateTime
to render as<input type="datetime-local" ... />
So, remove this change and instead update TemplateRenderer.GetTypeNames()
. Note InputTagHelper
and DefaultEditorTemplates
both use that method. Specifically, change TemplateRenderer
lines 208-210 to return "datetime-local"
for the DateTime
and DateTimeOffset
types. That way, [DataType(...)]
should still work but the defaults will be valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't we change this here? I'm pretty sure we don't ever want to render type="datetime"
because it is not spec-compliant, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 3 cases and I thought you wanted to change only (1) below. @jbagga's changes cover (1) and (2). If that's what you want, her source changes are fine and the main bit is confirming all 3 cases are covered for HTML and tag helpers.
- Property has type
DateTime
orDateTimeOffset
. - Property has some random type and an associated
[DataType("datetime")]
. - Property has whatever type but user either entered
<input type="datetime" ...>
or included[type]: "datetime"
in theirhtmlAttributes
dictionary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, @Eilon please confirm your intent. Obviously my leaning was toward changing only case (1) because (2) seems more like an explicit ask for type="datetime"
. But, I can see (2) is not that much more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dougbu So the change in TemplateRenderer
lines 208-210 to return "datetime-local" will cover (3)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the change in
TemplateRenderer
lines 208-210 to return "datetime-local" will cover (3)?
No, nothing you're changing will affect that case. The tag helper does not override an explicit type
attribute and your changes as well as my suggestion stick to the realm of defaults.
@dougbu I am not sure which PR comments (above) about the tests still apply. Most were related to (2), which we have decided to change behavior of. I apologize if the comments are still relevant. Please let me know and I will change them right away. |
@jbagga sorry, machine was partially frozen for a bit… We should cover the (2) cases in our tests i.e. ensure |
@dougbu Updated |
[InlineData("Time", Html5DateRenderingMode.Rfc3339, "{0:HH:mm:ss.fff}", "time", "time")] | ||
[InlineData("NullableDate", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-dd}", "date", "date")] | ||
[InlineData("NullableDateTime", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-ddTHH:mm:ss.fff}", "datetime", "datetime-local")] | ||
[InlineData("NullableDateTimeOffset", Html5DateRenderingMode.Rfc3339, "{0:yyyy-MM-ddTHH:mm:ss.fff}", "datetime", "datetime-local")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move new dataTypeName
parameter and data before expectedFormat
.
@@ -967,7 +969,9 @@ public void Process_GeneratesFormattedOutput(string specifiedType, string expect | |||
{ | |||
{ "type", expectedType } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this line to use the new dataTypeName
parameter. Don't make the changes a couple of lines below.
[InlineData("datetime", "datetime-local", null, "2000-01-02T03:04:05.060")] | ||
[InlineData("datetime-local", "datetime-local", null, "2000-01-02T03:04:05.060")] | ||
[InlineData("time", "time", "{0:t}", "03:04:05.060")] | ||
public void Editor_AppliesRfc3339(string dataTypeName, string expectedType, string editFormatString, string expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move expectedType
last or right after editFormatString
.
[InlineData("datetime", "datetime-local", null, "2000-01-02T03:04:05.006")] | ||
[InlineData("datetime-local", "datetime-local", null, "2000-01-02T03:04:05.006")] | ||
[InlineData("time", "time", "{0:t}", "03:04:05.006")] | ||
public void Editor_FindsCorrectDateOrTimeTemplate(string dataTypeName, string expectedType, string editFormatString, string expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move expectedType
last or right after editFormatString
.
[InlineData("datetime-local", "datetime-local", Html5DateRenderingMode.Rfc3339)] | ||
[InlineData("time", "time", Html5DateRenderingMode.CurrentCulture)] | ||
[InlineData("time", "time", Html5DateRenderingMode.Rfc3339)] | ||
public void Editor_AppliesNonDefaultEditFormat(string dataTypeName, string expectedType, Html5DateRenderingMode renderingMode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move expectedType
last.
@dougbu Updated |
Addresses #4871
cc @dougbu