Jump to content

InputfieldFloatRange - A range slider InputField


eelkenet
 Share

Recommended Posts

Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild. 

EDIT: You can now install it directly from the Modules directory: http://modules.processwire.com/modules/inputfield-float-range/

 

What is it?

The missing range slider Inputfield for Processwire. 

What does it do?

This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
It includes a visible and editable value field, to override/tweak the value if required.  

Features

  • Min/max values
  • Precision (number of decimals)
  • Optional step value (Read more)
  • Optional manual override of the selected value (will still adhere to the rules above)
  • Configurable rounding of manually entered values (floor, round, ceil, disable)

Usage

  • Clone / zip repo
  • Install FieldtypeFloatRange, this automatically installs the Inputfield
  • Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field.
  • To render the field's value simply echo `$page->field`

Demo

A field with Min=0, Max=1, Step=0.2, Precision=2

RangeSlider-demo-1.gif.dfd7e4cca45326630ac9a235d54de38b.gif

Field with settings Min=0, Max=200, Step=0.25, Precision=2

RangeSlider-demo-2.gif.e9a3e6da022a6a26272e80c1127dd844.gif

 

Todo

  • Make the display-field's size configurable (will use the Input Size field setting) 
  • Hopefully become redundant

 

Changelog

008 (current version)
- Add composer.json and submit to Packagist, making the module installable via composer

007
- Add defaultValue field (as requested by @charger)
- Fix a silly mistake where a negative rounding (-1) resulted in removing all decimals instead

006
- Fix bug where InputfieldFloat negative precision prevented the displayed value to be updated properly
- Revert installs & requires, so direct installs from Modules Directory (should) work

005
- Fix bug where the Inputfield would not work properly within repeaters / repeater matrices

004
- Make rounding of manually entered values configurable (floor, round, ceil or disable)
- Fix small JS bug where the value-display field was not displayed
- Update README

003
- Code cleanup, add some ModuleInfo data & LICENSE
- Submit to PW Modules directory (http://modules.processwire.com/modules/inputfield-float-range/)

002
- Fix issue where setting the step value to an empty value created problem with validation
- Make the display-field optional

001
- Initial release

 

 

Thanks!

 

 

  • Like 9
  • Thanks 1
Link to comment
Share on other sites

48 minutes ago, bernhard said:

Hi @eelkenet, thx for sharing ? Did https://modules.processwire.com/modules/range-slider/ not work for you or did you need other features? Would be nice to see the differences between your modules.

To be honest I didn't check out that module in a long time, and had even forgotten it existed.. ?

But the major differences would be FieldtypeRangeSlider is a full-fledged module with its own API, depends on jQueryUI, and.. has not been updated in 5 years. The one I created is much simpler and light-weight: it's really just a basic HTML5 <input type='range'> with some styling, feedback and validation. As such, it is just another way to use the regular Float/Integer inputfields.  

  • Like 5
  • Thanks 1
Link to comment
Share on other sites

The module has been updated to 004 005. Besides a small JS bugfix, this update makes the rounding of manually entered values configurable (floor, round, ceil or disable completely). 

Edit: As of version 005 it also works within repeaters / repeater matrix, thanks to @Robin S' help

Edited by eelkenet
Updated to 005
  • Like 1
Link to comment
Share on other sites

  • 3 years later...

Would be cool if the field allows for a default value (next to min and max), so e.g. when min is 0 and max is 1, it currently defaults to 0.5, but I would sometimes prefer the default to be 0. @eelkenet would this be complicated to implement?

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...