Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Add default editor templates for all numeric types, including short, ushort, and double, etc. #2261

Closed
weitzhandler opened this issue Mar 25, 2015 · 9 comments

Comments

@weitzhandler
Copy link

Hi.

Please have a look at this post.

It addresses what the System.ComponentModel.DataAnnotations.DataType attribute is here for.

Anyway, as per the closing note, only the following numeric types are supported:

type=number
int
byte
sbyte
uint
long
ulong
DataType enum
PhoneNumber (tel)
EmailAddress (email)
Url (url)
Date (date)
Time (time)
DateTime (datetime)

I'd like to ask you to please include short in the numeric category as well.

@danroth27
Copy link
Member

@dougbu Can you check if short is actually supported?

@dougbu
Copy link
Member

dougbu commented Mar 26, 2015

@weitzhandler server-side we simply execute any ValidationAttribute or subclass we find. client side we do two things:

  1. special-case some attributes for Unobtrusive client-side validation e.g. [EmailAddress] and [Compare]
  2. if you use @Html.Editor(), @Html.EditorFor(), or the <input/> tag helper, generate <input/> elements with the appropriate type attribute based on [DataType] (and the property type). this allows browsers to validate the inputs.

I suspect the scenario you've opened this issue about is 2. in my list -- where we generate <input type="number" .../> and where we don't. your type=number list above matches what we have in both MVC 5 and 6.

please confirm your request is for helper calls such as @Html.EditorFor(m => m.ShortProperty) to generate <input type="number" .../>.

@weitzhandler
Copy link
Author

@dougbu
Yes that's exactly what I meant.

@dougbu dougbu changed the title Please include all numeric types under DataType.Number Add default editor templates for short and double Mar 26, 2015
@dougbu
Copy link
Member

dougbu commented Mar 26, 2015

updated subject to reflect what would need to change here.

@weitzhandler In the meantime you could create a Shared/EditorTemplates/Short.cshtml file containing for example

@model short
@Html.TextBoxFor(m => m, htmlAttributes: new { type = "number" })

@weitzhandler
Copy link
Author

I'd also recommend adding those templates for ushort and all the other CLR primitive numeric types.

@weitzhandler weitzhandler changed the title Add default editor templates for short and double Add default editor templates for all numeric types, including short, ushort, and double, etc. Mar 26, 2015
@Eilon Eilon added this to the 6.0.0-beta5 milestone Mar 26, 2015
@Eilon Eilon assigned Eilon and dougbu and unassigned Eilon Mar 26, 2015
@weitzhandler
Copy link
Author

@Eilon and @dougbu here's your friend, I'd be happy to participate and do it myself, if that's an option.
And BTW, I don't see any reason not to have decimal as an <input type="number" /> as well.

@dougbu
Copy link
Member

dougbu commented Mar 29, 2015

not sure what I should include in the template, since I want the validations to be generated as well

do you mean validation attributes? should get those automatically with what I recommended:

@model short
@Html.TextBoxFor(m => m, htmlAttributes: new { type = "number" })

or, if you prefer tag helpers

@model short
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
<input asp-for="@Model" type="number"/>

otherwise feel free to include @Html.ValidationMessageFor(...). one downside is that would be very inconsistent with the default templates.

don't see any reason not to have decimal

decimal is already special-cased w.r.t. formatting. but you are correct that the <input/> tag helper and @Html.Editor() currently use the basic type="text" for that type.

@weitzhandler
Copy link
Author

As you can see @dougbu, I've already deleted the 2nd half of your question, I missed what you wrote about using the TextBoxFor in this post.

I'm sure you're responding by email, so you didn't get the updated version...

Thanks!

dougbu added a commit that referenced this issue Apr 7, 2015
- #2261
- include `short`, `ushort`, `float`, `double`

- correct typo in `<input/>` tag helper; ignored calculated format
 - only one test for `<input/>`'s calculated format 😦
- fill some `Editor*()` and `<input/>` tag helper test gaps

nit: clean up some trailing whitespace
dougbu added a commit that referenced this issue Apr 8, 2015
- #2261
- include `short`, `ushort`, `float`, `double`

- correct typo in `<input/>` tag helper; ignored calculated format
 - only one test for `<input/>`'s calculated format 😦
- fill some `Editor*()` and `<input/>` tag helper test gaps

nit: clean up some trailing whitespace
@dougbu
Copy link
Member

dougbu commented Apr 8, 2015

fixed in 73e8fc1

@dougbu dougbu closed this as completed Apr 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants