Problem/Motivation

When editing a numeric field there is no option to select how to display the field.

We should be able to choose between 'number' and 'range'.

Proposed resolution

  1. Add 'range' to Manage Form Display.
  2. Add an <output /> field like <input type=range min=0 max=100 value=50 id=fader step=1 onchange="outputUpdate(value)"><output for=fader id=volume>50</output> with a script like <script>function outputUpdate(vol) { document.querySelector('#volume').value = vol;}</script>
  3. Add option for <datalist />

How to test

  1. Add "Number (integer)" field
  2. Set Form display to "Range field"
  3. Note 'No placeholder' text (should not be displayed or entered)
  4. Configure Form field
  5. Check 'Display current value' (this is not always needed depending on theming)
  6. Note missing <datalist /> list options. See remaining tasks.

Remaining tasks

  • The value(s) must be visible while changing. There is no min, max or current visible. Where to put the javascript for updating this <output /> element. Note this is solved with a working <datalist/> as that provides labels.
  • Fix hardcoded <output/> tag from template file.
  • Fix placeholder settings as these are not needed
  • Do we want <datalist /> as w3c html5 forms input range which gives at least some stops. It should support labels but currently not on Mac+Chrome/Firefox/Safari

User interface changes

API changes

Issue fork drupal-2332833

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

clemens.tolboom’s picture

Component: field_ui.module » field system

@Berdir suggests to make this a widget.

@xjm suggest to make this contrib.

Status: Needs review » Needs work

The last submitted patch, core-number-range.patch, failed testing.

larowlan’s picture

+1 for widget

clemens.tolboom’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.18 KB
new2.11 KB

Attached patch makes it a widget which is indeed much better.

According to http://www.w3.org/TR/html5/forms.html#range-state-(type=range) we can add a datalist.

<input list="points" max="10" min="0" name="point" step="1" type="range" value="0" />
<datalist id="points">
  <option label="0" value="0" label="0"></option>
  <option value="5"></option>
  <option label="10" value="10" label="10"></option>
</datalist>

This only renders in Chrome but without labels.

With and without a data list

clemens.tolboom’s picture

Issue summary: View changes
StatusFileSize
new4.63 KB
swentel’s picture

Wicked !

One nitpick

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberRangeWidget.php
@@ -0,0 +1,39 @@
+ * Plugin implementation of the 'number' widget.

I guess this should say something like 'range number' ?

clemens.tolboom’s picture

StatusFileSize
new1.19 KB

@swentel I fixed for #6

What about the remaining tasks? Where to put the current value? Should we try to add the datalist?

swentel’s picture

Issue tags: +Needs UX Guideline, +Needs usability review

@clemens.tolboom Hmm, I'm no user interface specialist - we should get bojhan or yoroy here for some advice.

pepperstreet’s picture

Just found your blog post via G+, can't really help with coding because of very limited knowledge in Drupal.
But I recently came across this D7 module:
Slider Field (D7)
Maybe a good source (for inspiration)?

Regarding HTML5 range, here is an interesting article… see under "Show and Tell":
Playing With The HTML5 range Slider Input

clemens.tolboom’s picture

@swentel I'll try to contact bojhan or yoroy

@pepperstreet thanks for the links ... we checked with jqueryui-slider on our D8 headless UI and did a 'Show and Tell'.

Puzzle is should we fix this in core? How much should we add? Or just let go and wait for a contrib?

My hunch is provide the widget in core (out of the box) with small jQuery UI support.

clemens.tolboom’s picture

StatusFileSize
new2.45 KB

I'm trying to create a new twig for input range input--range.html.twig for the <output /> field but it is never found by the theme system. Why?

For the datalist we need same code as used by modules/options/src/Plugin/Field/FieldType/ListItemBase.php

clemens.tolboom’s picture

Issue summary: View changes

How/where do we add javascript for the widget?

clemens.tolboom’s picture

Issue summary: View changes
star-szr’s picture

To add a new template like that to a module you need to declare it in hook_theme() as input__range and specify the base hook. See comment_theme() and node_theme() for examples.

clemens.tolboom’s picture

Issue summary: View changes
StatusFileSize
new2.93 KB

Field is now themed 'correctly'. See remaining tasks. Please take over this issue :-)

star-szr’s picture

Issue summary: View changes

Fixing runaway code tag in the issue summary. I'm not working on feature requests right now though.

Status: Needs review » Needs work

The last submitted patch, 16: allow_range_when-2332833-16.patch, failed testing.

Bojhan’s picture

Issue tags: -Needs usability review

Nothing to review at this point.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xjm’s picture

Issue tags: -needs UX guidelines +Needs usability review
xjm’s picture

Version: 8.6.x-dev » 8.9.x-dev
clemens.tolboom’s picture

Issue tags: +Needs reroll
swatichouhan012’s picture

Status: Needs work » Needs review
StatusFileSize
new2.46 KB

Rerolled patch#11 wrt 8.9.x

hash6’s picture

Assigned: Unassigned » hash6

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

hardik_patel_12’s picture

StatusFileSize
new2.46 KB

Re-roll for 9.1.x-dev

hardik_patel_12’s picture

Kindly ignore last patch , because patch at #34 and #31 are identical , i am triggering test for 9.1.x branch on #31. So patch at #34 is not needed sorry for that.

clemens.tolboom’s picture

Not sure why but credit and commit did not have my name in it? I have seen in more issues that author changed from initial to others.

Guess I cannot fix this but this is my try :-)

clemens.tolboom’s picture

Assigned: hash6 » Unassigned

That did not work out as expected. Guess changing these `Credit and committing` is file attachment based?

jofitz’s picture

Issue tags: -Needs reroll

Removed "Needs reroll" tag.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joaopauloc.dev’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new11.09 KB
new9.42 KB
new6.55 KB
new19.66 KB
new21.44 KB
new18.74 KB

Patch #31 was applied and works fine.

Steps followed.
1 - Create a number field in the page content type
2 - Change the field widget to the Range field on the manager form display
3 - Crate a new node of the content page and I could see the range field
4 - Edited the node created and changed the value to check if the got the correct value.
5 - Update the field number by adding min and max value options.
6 - Created another node and I could see the range respecting the min and max value.

See all attachments for evidence.

Hey @xjm, I updated this issue to reviewed and tested by the community status, after @bojhan comment on #21.
Should we keep this status or do we need to wait for another approval?
Thanks.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new2.33 KB

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joaopauloc.dev’s picture

Assigned: Unassigned » joaopauloc.dev

On it, fixing the php cs and adding unit test to new widget created

joaopauloc.dev’s picture

Assigned: joaopauloc.dev » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs change record
StatusFileSize
new8.78 KB

This still needs a usability review but just from my observations

sldier

There is no way to tell the current value.
When I saved this page the view mode said the value was 66 but I had 0 idea.

camchandler98’s picture

Assigned: Unassigned » camchandler98
StatusFileSize
new7.29 KB

I thought adding a display for the slider would be just quickly editing the twig template but boy was I wrong. Long story short I ended up twig debugging and saw that the range input is still using the default input template Twig debug output default input selected.
I think I know what to do now though so I will work on it.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.