No commit activity in last 3 years
No release in over 3 years
This gem can imitate input[type="number"]
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.12
~> 10.0
 Project Readme

TypeNumberImitate

jQuery-library to imitate input[type='number'] for input[type='text']

WARNING: jQuery and Lodash required.

Attributes step (default 1), min, max are supported.

Use attribute float (default false) to allow float typing.

Handlers on keyboard up (↑) and down (↓) changes value of input on step

Installation

Add this line to your application's Gemfile:

gem 'type_number_imitate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install type_number_imitate

Usage

<input class="first" float="" min="1" type="text">
new TypeNumberImitate('input.first');

Result:

<div class="type-number-imitate">
  <input autocomplete="off" class="cart_variation_quantity" min="1" name="cart_variation[quantity]" placeholder="1" value="1">
  <span class="plus">+</span>
  <span class="minus"></span>
</div>

Options

  new TypeNumberImitate(inputSelector, options);
  • wrapperClasses - additional classes for wrapper div.type-number-imitate
  • plusClasses, minusClasses - additional classes for plus and minus spans
  • skipPlaceholder - Use this attribute to clear placeholder. By default placeholder is set from placeholder-attribute, if it's absent placeholder is set as min-attribute.
  new TypeNumberImitate('input.second', {wrapperClasses: 'green-border large'});

All options are available from data-tni-ATTR i.e:

<input class="first" float="" min="1" type="text" data-tni-wrapper-classes='green-border large'>

Live demo

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/type_number_imitate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.