[whatwg] Form input element for value-unit pairs

Jukka K. Korpela:
> Christoph P?per wrote:
> 
>>  <input type="number" id="fontsize" value="12" unit="pt">
> 
> Or do you mean that the presence of the unit="..." attribute would trigger a special implementation of numeric input, so that the user is expected to enter both a number and a unit, with the latter defaulted according to the unit attribute?

Yes. 

UIs may autoconvert the value if the unit changes or keep it. I?m not sure which solution is better.

> Although the need for number & unit input is relatively common, I think it can quite satisfactorily be handled using a number input field and e.g. a dropdown menu of units accepted by an application (or maybe a textfield). After all, processing of the form data would most probably want to split a combined number & unit data item into its components, so why put them together in the first place?

Usability.

Maybe it would work better with ?datalist?:

  <input name=fontsize type=number unit=typo>
  <datalist id=typo>
    <option value=2.835 label=pt>
    <option value=1 label=mm>
  </datalist>

or

  <input name=fontsize type=number unit=#typo>
  <datalist id=typo>
    <option value=pt label=point>
    <option value=mm label=millimetre>
  </datalist>

Received on Tuesday, 15 March 2011 09:36:41 UTC