I want to make an input field where the user can only enter a number. In HTML5, we can use <input type="number">. How do I do this in blade?
I tried this:
{!! Form::number('amount', null, array('class' => 'form-control')) !!}
I could search and code it. Since there was no direct answer, I thought to post the working code below:
{!! Form::input('number', 'amount', null, ['class' => 'form-control']) !!}
You can use either Form::input() method or Form::number() method to achieve your goal.
Form::input() method
This method takes 4 arguments.
Example:
{{ Form::input('number', 'name') }}
{{ Form::input('number', 'name', 'value', ['class' => 'number', 'id' => 'numberField']) }}
//both example will create elements like this
<input name="name" type="number" value="value">
<input name="name" type="number" value="value" class="number" id="numberField">
Form::number() method
This method takes 3 arguments.
Example:
Form::number('name')
Form::number('name', null, ['class' => 'number', 'id' => 'numberField'])
//both example will create elements like this
<input name="name" type="number">
<input name="name" type="number" class="number" id="numberField">
Tips: if you want to use
$optionsand don't want to assign any default value, usenullat the$valueargument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With