Problem/Motivation

Multiple-value select lists include a convenience '- None -' option but it is not selected by default. This leaves the end-user confused as to whether or not to they should select the '- None -' option, or instead not select any option.

Updated Steps to reproduce:

  1. Install Base Drupal 8
  2. Click Menu -> Structure -> Taxonomy
  3. Click Add Vocabulary and add a sample vocabulary like "Automobiles"
  4. Add Terms like " 1) Cars, 2) Bikes, 3) Trucks"
  5. With this the taxonomy is created.
  6. Go back to Menu-> Structure -> Content Types
  7. You should see Article and Basic Page listed here. Click the dropdown near to edit on "Article" row and select Manage Fields
  8. You will see list of fileds in the contet type like title,body etc
  9. In the bottom, there is a text filed labeled "Add a new Field". Type a Label - "Atuomobile" here
  10. On the select box in the same row, click the dropdown "Select a field type" and select term reference
  11. The widget column "widget" should be select list. Hit Save
  12. In the next page, change "Maximum number of values users can enter" to "Unlimited" and hit save
  13. Yet another page opens with the Field label and a text area and at the bottom , the option to select "Default Value" for the field. Select "None" and Click "Save Settings"
  14. You are all set. Close the light box by clicking the "X" at the top right. Let us test the feature
  15. Click Menu -> Content
  16. Click the Blue "Add Content" Button and select Article
  17. Give a title and skip the rest and look at the Taxonomy field that you added earlier near the bottom of the page
  18. Your selection "None" should be highlighted here
  19. With the basic Drupal 8 install, None is not highlighted for me

Proposed resolution

Modify either FormAPI or the field module in order to have the '- None -' option selected by default only if there are no saved or default value(s) for the select list.

Remaining tasks

Reviews needed, tests to be written

User interface changes

On multiple-value select lists, the '- None -' option will be selected by default.

Original report by @mbutcher

When adding a select widget for a taxonomy term to my field, I cannot set the default field to "-None-".

Steps to reproduce:

  • Add a taxonomy term field to a node type.
  • Set the widget type to "Select list"
  • On the settings for the widget, set the "Default value" to "-none-"

Save

Outcome:

"-None-" is no longer highlighted, nor is it marked as the default on an article edit form.

Expected:

In both forms I expect "-none-" to be marked as the default.

This has been a source of confusion to our users, who don't know if they need to select "-none-" or leave it unselected.

https://img.skitch.com/20111221-dd52pfaa9aaxpcnxdih34kp939.png

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

I can't reproduce this. Have you any other settings or enabled modules that may be relevant?

yched’s picture

Component: field system » taxonomy.module

Re-categorizing

xjm’s picture

Version: 7.x-dev » 8.x-dev

I was also unable to reproduce this in D8. Could you give exact steps to reproduce, like maybe the particular vocabulary and terms? Or even a test case that replicates your config?

Maybe related: #1381140: A #default_value = 0 for #type radios checks all radios.

xjm’s picture

Status: Postponed (maintainer needs more info) » Active

Oh! I figured out how to reproduce it. It needs to be a multiple value field, as in the screenshot

xjm’s picture

And actually this appears to be a field/forms issue, because it also happens with a mutlivalue text list field.

yched’s picture

Hm, true, that's actually not allowed by Field API.
'- None -' comes back as "no value", and "no value" means we don't store any "default value specified" (just like, if the widget was a textbox, we would treat 'empty string' as 'no default value was specified'), and therefore nothing gets preselected on entity creation forms.

On non-multiple selects, the '- None -' option does come preselected, but that's only the usual behavior of select dropdowns, the 1st value shows as selected if no explicit value is set.

I don't think I see a workaround. I'd tend to mark this "by design".

xjm’s picture

Yeah, the "None" option is really just a convenient way to deselect other options you may have selected. On the other hand, I do see the UX issue with it not being selected by default.

Bojhan’s picture

I see no reason, why we wouldn't allow this to be a default value - I imagine there be challenges from a back-end perspective, but even if its only on display, it should solve the issue.

xjm’s picture

Title: Taxonomy field with select list does not allow "-None-" to be a default value » Field with select list does not allow "-None-" to be a default value
Component: taxonomy.module » field system

Moving back to field land.

xjm’s picture

Title: Field with select list does not allow "-None-" to be a default value » Field with multiple select list does not allow "-None-" to be a default value
xjm’s picture

Let's add an automated test for this to get this issue rolling. Also let's add a full issue summary including the info from #4 and #5.

joachim’s picture

> On non-multiple selects, the '- None -' option does come preselected, but that's only the usual behavior of select dropdowns, the 1st value shows as selected if no explicit value is set.

If that's the case on single-value selects, surely the fix for this belongs in FormAPI land, and is to make the convenience 'None' option preselected on multi-value selects.

Otherwise, if we only fix this in FieldAPI, we'll have a UI inconsistency.

gaas’s picture

This is my attempt at a patch for this. Unfortunately I still get a test failure for OptionsWidgetsTest::testRadioButtons that I don't really understand.

For non-required single-value fields there will be radiobutton with a "N/A" entry that should be selected. The patch fixes that case as well.

gaas’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, make_none_selected-1379070-13.patch, failed testing.

kid_icarus’s picture

Status: Needs work » Needs review
FileSize
1.98 KB
855 bytes

Here is my attempt to address the issue in FormAPI land.

The test provided is similar to @Gisle's, only that it asserts '_none' is selected in the multi-value test instead of the single value test.

I'm uncertain as to whether my version of the fix is valid, and furthermore, if the provided assertion would be better suited to live in another test (specifically a form test, rather than a field test).

Feedback much appreciated :)

Status: Needs review » Needs work

The last submitted patch, make_none_selected-1379070-16-complete.patch, failed testing.

kid_icarus’s picture

Issue summary: View changes

Added Issue Summary

kid_icarus’s picture

Issue summary: View changes

Updated issue summary.

kbk’s picture

FileSize
21.33 KB

Could this problem apply to single-select term reference fields as well? When I select "N/A" as the Default Value > Save > revisit settings page > the Default Value is not set. If I choose an actual term, the Default Value is retained.

YesCT’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs issue summary update, -Needs backport to D7

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update, +Needs backport to D7

The last submitted patch, make_none_selected-1379070-16-complete.patch, failed testing.

YesCT’s picture

Issue tags: +Needs reroll

tagging for reroll

rkjha’s picture

Patch rerolled

rkjha’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, make_none_selected-1379070-20-tests.patch, failed testing.

rkjha’s picture

I will have a look at what went wrong and will get the patch updated as soon as I get some time.

rkjha’s picture

Status: Needs work » Needs review
FileSize
1.91 KB

Patch rerolled and updated. Let us hope it passes this time.

star-szr’s picture

@rkjha - Thanks! An interdiff would be very helpful here :)

Status: Needs review » Needs work

The last submitted patch, make_none_selected-1379070-26-complete.patch, failed testing.

disasm’s picture

Thanks rkjha for the reroll. I was reviewing this, and a few things to note (completely unrelated to your excellent work rkjha):

1) The interface for this is not very good in my opinion. having a "None" option on a multi-select list is confusing. What if I select none and another tag? Will it just select the other tag, will the none override the other tag, will it be in some kind of pseudo state where it's both selected and unselected? In my opinion, the none makes perfect sense for the dropdown select, but for the multi-select, it should just have a list of tags, and then if none are selected, it marks it as having none selected.

2) The STR needs updated. An STR needs to be detailed enough that someone who has never worked on an issue can go through from start to finish. The first step should always be install D8, and we need steps for adding terms to the vocabulary, adding the field to the content type, creating new content page, etc...

Again, thanks for your hard work rkjha!

disasm’s picture

Issue summary: View changes

Updated issue summary.

zetagraph’s picture

Tried the STR on clean install and applied the patch in 26 manually. Seems to work for me and fixes the behaviour where the '- None -' option is now stays selected in the content type field settings and the node.

rkjha’s picture

What you have pointed out is great, disasm, but there is one issue that comes in my mind(which I feel remains unaddressed).
Suppose, for multi-select, I have a list of tags with none of them selected in the beginning(as you've proposed). I select some tags but soon realize that I didn't intent to select any. In this case, I have only two option. Either there is some "none" option, selecting which undoes the selection of rest all tags or there is some feature that one can deselect the tag by clicking it again.

attiks’s picture

#31 if you CTRL click on a selected option it will get deselected, works in most browser AFAIK. Only problem might be with mobile.

shariharan’s picture

Issue summary: View changes

Added couple steps to the STR for creating test vocabulary and terms.

shariharan’s picture

Issue summary: View changes

Updated Steps to Reproduce

shariharan’s picture

Updated Steps to reproduce:

  1. Install Base Drupal 8
  2. Click Menu -> Structure -> Taxonomy
  3. Click Add Vocabulary and add a sample vocabulary like "Automobiles"
  4. Add Terms like " 1) Cars, 2) Bikes, 3) Trucks"
  5. With this the taxonomy is created.
  6. Go back to Menu-> Structure -> Content Types
  7. You should see Article and Basic Page listed here. Click the dropdown near to edit on "Article" row and select Manage Fields
  8. You will see list of fileds in the contet type like title,body etc
  9. In the bottom, there is a text filed labeled "Add a new Field". Type a Label - "Atuomobile" here
  10. On the slect box in the same row, click the dropdown "Select a field type" and select term reference
  11. The widget coloumn "widget" should be select list. Hit Save
  12. In the next page change "Maximum number of values users can enter" to "Unlimited" and hit save
  13. Yet another page opens with the Field label and a text area and at the bottom , the option to select "Default Value" for the field. Select "None" and Click "Save Settings"
  14. You are all set. Close the light box by clicking the "X" at the top right. Let us test the feature
  15. Click Menu -> Content
  16. Click the Blue "Add Content" Button and select Article
  17. Give a title and skip the rest and look at the Taxonomy field that you added earlier near the bottom of the page
  18. Your selection "None" should be highlighted here
  19. With the basic Drupal 8 install, None is not highlighted for me

updated the issue summary

shariharan’s picture

Issue summary: View changes

moved the STR to the top

kshama_deshmukh’s picture

Assigned: Unassigned » kshama_deshmukh
Issue tags: +Mumbai-Drupal Sprint #6
yched’s picture

Component: field system » forms system

As stated in #6, and as the patches show, this is not related to Field API & the "select" widgets, that's how Form API's underlying 'select' #type works.
Re-categorizing.

yched’s picture

Issue summary: View changes

Adding back the original STR which I removed accidentally

YesCT’s picture

Assigned: kshama_deshmukh » Unassigned
Issue summary: View changes

unassigning. it has been a while. please post a comment back to pick this back up.

I think a little more hints about what tests are still needed would help.

YesCT’s picture

Issue tags: -Mumbai-Drupal Sprint #6 +Mumbai-Drupal Sprint 6, +Needs reroll

needs reroll, instructions: https://drupal.org/contributor-tasks/reroll

(changed the previous sprint tag, because it had a # in it, which is trouble after the d.o d7 upgrade, #2171455: d.o does not autocomplete tags starting with # hash anymore)

akozma’s picture

Assigned: Unassigned » akozma
Issue tags: +SprintWeekend2014
akozma’s picture

Status: Needs work » Needs review
FileSize
2.94 KB
2.02 KB

Re-rolling the patch from #26.

Status: Needs review » Needs work

The last submitted patch, 39: make_none_selected-1379070-39-complete.patch, failed testing.

The last submitted patch, 39: make_none_selected-1379070-39-complete.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
2.85 KB
1.6 KB

This will make it work - but I had to cheat a little in the optionsWidgetBase class. not sure yet whether that's the best approach, but tests should be green now.

akozma’s picture

@swentel, I don't know neither which is the best approach.
I made also a fix on patch #39, which pass the test. Maybe it will be useful.

swentel’s picture

That's indeed much saner :)

The last submitted patch, 42: make_none_selected-1379070-39-complete.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 43: make_none_selected-1379070-43-complete.patch, failed testing.

akozma’s picture

Status: Needs work » Needs review
FileSize
3.51 KB
1.25 KB

The patch failed on Drupal\taxonomy\Tests\TermFieldMultipleVocabularyTest, but as I see the patch is correct.

I checked the TermFieldMultipleVocabularyTest::testTaxonomyTermFieldMultipleVocabularies() function and it seems the call for testing the widget display should be changed.

Before:
$this->assertFieldByName("{$this->field_name}[]", '', 'Widget is still displayed.');
- this is searching for the select field with the value '', but we will never have that in this case.

After:
$this->assertFieldByName("{$this->field_name}[]", NULL, 'Widget is still displayed.');
- at this call we are interested to check if the widget displayed only, so NULL as value will ignore the checking for value also.

The value check are done in WebTestBase::assertFieldByXPath(), "if (isset($value)) {...}" , and because the isset on empty string is TRUE than the assertFieldByName actually search for the select with value ''.

miniwebs2’s picture

Status: Needs review » Reviewed & tested by the community

Working at a code sprint at DrupalSouth in Wellington - this was my first ever test of a patch (mentor beside me!!!!), we could confirm that the problem still exists in current Drupal core still exists.
Applied the patch (mentor still beside me!!!!) and we now confirm that the above patch at #47 does work and therefore makes the Default setting on 'None' stick.
Rechecked it on local dev and all good.
Seems RTBC (that's what the mentor said I write!!!)

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to 8.x, thanks!

Moving to 7.x for backport.

klonos’s picture

Sutharsan’s picture

Issue tags: -Needs reroll

... and to removing 'Needs reroll' tags when done ;)

akozma’s picture

Assigned: akozma » Unassigned
dcam’s picture

Status: Patch (to be ported) » Needs review
FileSize
3.25 KB

Backported #47 to D7.

Status: Needs review » Needs work

The last submitted patch, 53: make-none-selected-1379070-53.patch, failed testing.

dcam’s picture

Status: Needs work » Needs review
FileSize
3.26 KB
757 bytes

Oops. I didn't change the field ID in that line.

mgifford’s picture

I went through the steps to reproduce and it looks good. This will be a good improvement to D7.

You can also verify that None doesn't work in D7 Core now by just looking at the Content types as the value doesn't save right now - admin/structure/types/manage/article/fields/field_atuomobile

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Whoops, wanted to RTBC IT.

The last submitted patch, 55: make-none-selected-1379070-55.patch, failed testing.

dcam’s picture

Random test failures...

The last submitted patch, 55: make-none-selected-1379070-55.patch, failed testing.

The last submitted patch, 55: make-none-selected-1379070-55.patch, failed testing.

deanflory’s picture

Should this be applied to D7.31 or is does it still have issues? The testing fails are confusing (not really, but the retesting is).

dcam’s picture

Issue tags: -Mumbai-Drupal Sprint 6, -SprintWeekend2014

Those test failures were the result of a Test server issue. It was mistakenly configured to run with the wrong version of PHP. The issue was fixed. I thought I retested all of the affected issues, but I missed this one, probably because its status wasn't set to Needs Work.

I should note that Testbot auto-retests issues now and for 7.x will occasionally crash. This results in a test failure. Again, there is no issue with the patch. It just has to be retested and set back to RTBC.

The last submitted patch, 55: make-none-selected-1379070-55.patch, failed testing.

The last submitted patch, 55: make-none-selected-1379070-55.patch, failed testing.

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Component: forms system » options.module
Status: Reviewed & tested by the community » Needs work

Sorry, but this fix can't be right... The '_none' key only has special meaning with the Options module, so the form API shouldn't have any code that treats it specially.

At least in Drupal 7, isn't the actual bug in the Options module? I would expect it has something to do with this code...

/**
 * Transforms submitted form values into field storage format.
 */
function _options_form_to_storage($element) {
...
  // Filter out the 'none' option. Use a strict comparison, because
  // 0 == 'any string'.
  if ($properties['empty_option']) {
    $index = array_search('_none', $values, TRUE);
    if ($index !== FALSE) {
      unset($values[$index]);
    }
  }

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.

  • catch committed 13905ed on 8.3.x
    Issue #1379070 by ocsilalala, rkjha, swentel, kid_icarus, Gisle: Field...

  • catch committed 13905ed on 8.3.x
    Issue #1379070 by ocsilalala, rkjha, swentel, kid_icarus, Gisle: Field...

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.

sassafrass’s picture

This issue still exists in Drupal 7. Do we need to create a new ticket to address it in D7?

mgifford’s picture

@David_Rothstein Didn't this get fixed in D8 in #49?

I guess that "_none" is in this patch https://www.drupal.org/files/issues/make_none_selected-1379070-47-comple...

So if not "_none" what?

@sassafrass there is still a patch for D7 that might work. It still has this same issue with "_none".

  • catch committed 13905ed on 8.4.x
    Issue #1379070 by ocsilalala, rkjha, swentel, kid_icarus, Gisle: Field...

  • catch committed 13905ed on 8.4.x
    Issue #1379070 by ocsilalala, rkjha, swentel, kid_icarus, Gisle: Field...
praveen kumar R’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: +ChennaiSprint2017

I followed the above steps to reproduce the issue and it works fine with #47 patch file.

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.

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

@praveen kumar R

I do not understand what you reviewed. #47 is a 3-year-old patch that was committed.

@sassafrass A maintainer raised an issue in #70 about _none that hasn't yet been settled.

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.

AndrewTur’s picture

Hi,

I followed the steps in the summary and the issue seems fixed in 8.4.x.
But I'm a bit confused to what the comment #70 is about. What needs to be done for this issue to get resolved it would be helpful to update the summary so this can get moved along.

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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

shobhit_juyal’s picture

Issue summary: View changes

Made some correction in the issue description.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

quietone’s picture

Issue tags: +Bug Smash Initiative

This issue was committed back in Feb 2014 when Drupal 8 was in alpha. There is only one question here that needs to be answered.

Looking at form.inc the change is in 'form_select_options' which is for converting the options in a select element. That looks like the right place to make this change. So, move this to Drupal 7?

quietone’s picture

Version: 8.9.x-dev » 7.x-dev
Issue tags: -Needs backport to D7

Asked in #bugsmash and lendude agreed that this should be moved to Drupal 7.