# Number field type

**URL:** <https://discourse.getcockpit.com/t/number-field-type/393>\
**Category:** Support\
**Created:** [November 11, 2018, 4:31pm UTC](https://discourse.getcockpit.com/t/number-field-type/393 "2018-11-11T16:31:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![asckpit](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@asckpit](https://discourse.getcockpit.com/u/asckpit)\
**Post date:** [November 11, 2018, 4:31pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/1 "2018-11-11T16:31:03Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [November 11, 2018, 8:26pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/2 "2018-11-11T20:26:19Z")

</div>

Hi,

use the `text` type and add this to the field options

```auto
{
  "type": "number"
}

```

---

<div class="post-metadata">

**Author:** ![asckpit](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@asckpit](https://discourse.getcockpit.com/u/asckpit)\
**Post date:** [November 11, 2018, 9:36pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/3 "2018-11-11T21:36:16Z")

</div>

Amazing, thanks !

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

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [November 11, 2018, 9:44pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/4 "2018-11-11T21:44:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![asckpit](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@asckpit](https://discourse.getcockpit.com/u/asckpit)\
**Post date:** [November 11, 2018, 11:25pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/5 "2018-11-11T23:25:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [November 12, 2018, 3:13pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/6 "2018-11-12T15:13:55Z")

</div>

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]?))`

---

<div class="post-metadata">

**Author:** ![asckpit](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@asckpit](https://discourse.getcockpit.com/u/asckpit)\
**Post date:** [November 12, 2018, 3:27pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/7 "2018-11-12T15:27:57Z")

</div>

Hi,

I tried again, but no success.

 ![23](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/528afa61de0c15f6152f8288d38132c733934fb9.png)

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

```

(Version 0.8.3)

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [November 12, 2018, 6:23pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/8 "2018-11-12T18:23:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![asckpit](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@asckpit](https://discourse.getcockpit.com/u/asckpit)\
**Post date:** [November 12, 2018, 6:59pm UTC](https://discourse.getcockpit.com/t/number-field-type/393/9 "2018-11-12T18:59:50Z")

</div>

Hi, I’m using Chrome / Version 70.0.3538.77

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [November 13, 2018, 9:40am UTC](https://discourse.getcockpit.com/t/number-field-type/393/10 "2018-11-13T09:40:27Z")

</div>

Use the value inside `""`:

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

```

![image](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/d69592812dbffe5bb50218dbe32cda06366082c0.png)

---

<div class="post-metadata">

**Author:** ![asckpit](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@asckpit](https://discourse.getcockpit.com/u/asckpit)\
**Post date:** [November 13, 2018, 10:36am UTC](https://discourse.getcockpit.com/t/number-field-type/393/11 "2018-11-13T10:36:52Z")

</div>

Ha, well seen, thanks !
