reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

Limiting input with {:field :numeric} to #60

Closed kishanov closed 9 years ago

kishanov commented 9 years ago

Hi there,

I've noticed that [:input {:field :numeric}] generates <input type="text">. This is OK, but when I try to limit the input to specific range (let's say 1..65536) there is somewhat strange behavior:

Is there a reliable way to make input field accept only N characters at max OR maximum input number?

kishanov commented 9 years ago

After some research I've found the solution and I'll close the issue, but I'd like to outline the solution for posterity.

Basically {:maxLength 5} is working (notice capital 'L'), while {:maxlength 5} is not. According to react doc (https://facebook.github.io/react/docs/tags-and-attributes.html) capitalization matters. However, the result is compiled into lowercase "maxlength" (can be observed through developer tools)

yogthos commented 9 years ago

As a note you should also be able to use Clojure idiomatic :max-length as well and Reagent is smart enough to handle it.

kishanov commented 9 years ago

Dmitri, thanks for the hint.

Just out of curiosity, what is the justification for generating <input type="text"> for {:field :numeric} and not <input type="number">?

yogthos commented 9 years ago

As I recall, when I tested with some older IE versions I got better results with type text, so I decided to go with it for compatibility reasons.