<p>Not tested yet.</p>

<pre><code>{{ forms.textField({
        label: 'Number Field',
        id: 'someId',
        name: 'someName',
        value: '',
        min: 0,
        max: 100,
        size: 1,
        type: 'number',
        value: settings['someName']
    })
    }}
</code></pre>

<p>I think you can use <code>min</code> and <code>max</code></p>

CC BY-SA 4.0
2019-06-01T06:53:33.837Z
2019-06-01T06:53:33.837Z
inrsaurabh
<p>I haven't found any fields that deal with numbers for a plugin. I've changed a <code>forms.textField</code> into a <code>type:number</code> which has seemed to work fine for the most part. But I can't find a way to keep someone from going under 0 or over 100. I've looked in <code>vendor\craftcms\cms\src\templates\_includes</code> and have come up empty.</p>

<p>I'm assuming I'll need to make a custom field type for this but if there is something I'd rather not reinvent the wheel.</p>

<pre><code>  {{ forms.textField({
      label: 'Blanket Discount Percent',
      instructions: 'Set this if you want to offer a blanket discount to all businesses. Do not put in letters or decimals. (10 = 10%)',
      id: 'blanketDiscount',
      name: 'settings[blanketDiscount]',
      value: settings.blanketDiscount,
      type: 'number',
   })}}
</code></pre>

<p>I do have a rule for validation setup, I would just prefer to keep people in range at the front as well.</p>

<pre><code>['blanketDiscount', 'integer', 'min' =&gt; 0, 'max' =&gt; 100],
</code></pre>

CC BY-SA 4.0
2018-09-21T19:07:32.683Z
Not an answer to your question, but the reason there isn't a number macro by default in Craft is that it's very US-centric formatting (commas for thousands separator, period for decimal) and that's not true everywhere.
Brad Bell
<plugin-development><fieldtypes>
Type number form in textField for plugin
# Type number form in textField for plugin

(Asked by: username_0 on 2018-09-21)

I haven't found any fields that deal with numbers for a plugin. I've changed a forms.textField into a type:number which has seemed to work fine for the most part. But I can't find a way to keep someone from going under 0 or over 100. I've looked in vendor\craftcms\cms\src\templates\_includes and have come up empty.
I'm assuming I'll need to make a custom field type for this but if there is something I'd rather not reinvent the wheel.
  {{ forms.textField({
      label: 'Blanket Discount Percent',
      instructions: 'Set this if you want to offer a blanket discount to all businesses. Do not put in letters or decimals. (10 = 10%)',
      id: 'blanketDiscount',
      name: 'settings[blanketDiscount]',
      value: settings.blanketDiscount,
      type: 'number',
   })}}

I do have a rule for validation setup, I would just prefer to keep people in range at the front as well.
['blanketDiscount', 'integer', 'min' => 0, 'max' => 100],

**Tags:** plugin-development, fieldtypes

> **Comments:**
> **username_1**: Not an answer to your question, but the reason there isn't a number macro by default in Craft is that it's very US-centric formatting (commas for thousands separator, period for decimal) and that's not true everywhere.  

---

## 1 answers

### Answer by username_2 on 2019-06-01. Score: 1 | Accepted answer

Not tested yet.
{{ forms.textField({
        label: 'Number Field',
        id: 'someId',
        name: 'someName',
        value: '',
        min: 0,
        max: 100,
        size: 1,
        type: 'number',
        value: settings['someName']
    })
    }}

I think you can use min and max


---

