开发者

GUI control for representing amount of time

开发者 https://www.devze.com 2023-01-04 08:20 出处:网络
I have an input asking the submitter how long an event took. Right now it\'s a normal textbox that should error out if anything but an integer is submitted. I tell the submitter to input the length in

I have an input asking the submitter how long an event took. Right now it's a normal textbox that should error out if anything but an integer is submitted. I tell the submitter to input the length in whole minutes.

However, thinking in minutes isn't the brains best ability... Nei开发者_开发知识库ther is following instructions, so I often get "support-requests" that state that "my input of 1,5 hours didn't work".

Is there any good way of requesting the user to submit a length of time, and accepting other than minutes in return?


Why won't you make your control a bit more intelligent and allow this to be entered: 1h, 40m, 1.5h, 1,5h, 2d5h, etc. Optionally, you can "AJAXly" parse this value on the server side and provide a side-by-side hint, which will state how exactly your program will interpret the value.

                -----------------
Enter Timespan: | 2d1.5h        |   (2 days and 1.5 hours, 25.5 hours total)
                -----------------

Additionally, you can use some reasonable defaults, like 1.5 (or 1,5) is most likely 1.5 hours, not 1.5 minutes, and should be interpreted as such. 0,5 is not 30 seconds as well, but rather 30 minutes, etc.


An easy way to do this would be to have a box accepting floating point input and another control to select units. For example

Time: [ 4.1     ] [ hours ] <- select units from this drop down box
Time: [ 0.5     ] [ days  ]
Time: [ 1e-3    ] [ years ]

Your server code can enumerate the units for generating the control and interpreting the submission.

The explicit mention of the units in the control right next to the number entry should help with users not reading instructions — they're probably far more likely to do the right thing if it's there with the data they're entering, than to read every little detail in the fine print a paragraph above it.

(Having said that, I really like Anton Gogolev's answer too. If you can pull it off, do that.)


You can display several input boxes accepting integers, each for a specific unit of time:

Time:  [  1 ] day  [  4 ] hours    [ 26 ] minutes   [ 42 ] seconds

The user can fill any single box or both.

0

精彩评论

暂无评论...
验证码 换一张
取 消