Number field type


#1

Hi,

Is there any “number” field type ?

Do I have to use a “text” type with a custom pattern like “[0-9]+(.[0-9]+)?” to simulate such type ? In that case the admin isn’t providing a suitable UI for numbers (no arrows or shortcuts to increment/decrement…).

I don’t see a “number” type in the docs. Did I miss something ?


Api returns int for text value?
#2

Hi,

use the text type and add this to the field options

{
  "type": "number"
}

Api returns int for text value?
#3

Amazing, thanks !

Is there a min/max option or other number-related ones, and are they documented somewhere (source included) ?


#4

as far as I know you can set all attributes that you could also set on an html input.

so

{
  "type": "number",
  "min" : 0,
  "max" : 10
}

should do the trick

no guarantee!


#5

That’s what I thought too but it doesn’t !


#6

Humm it should work, the textfield accepts the following attributes:

['maxlength', 'minlength', 'step', 'placeholder', 'pattern', 'size', 'min', 'max']

You can also pass a regex pattern in the field and do the validation using html5:

for example a max between 0 and 5000

(5000|([1-4]?[0-9]?[0-9]?[0-9]?))


#7

Hi,

I tried again, but no success.

{
  "type": "number",
  "min": 0
}

(Version 0.8.3)


#8

note that min and max are html5 input-field attributes - are you perhaps using a browser that does not support the min and max attrib on inputs?


#9

Hi, I’m using Chrome / Version 70.0.3538.77


#10

Use the value inside "":

{
  "type": "number",
  "min": "0",
  "max": "15"
}

image


#11

Ha, well seen, thanks !