I have a hierarchical vocabulary used by a term reference field. The field is optional, allows multiple, and has these settings:
- Do not allow creation of new items
- Do not force selection of deepest level

The bug is that any terms set to "None" aren't unselected if a term is added immediately after using "Add another one".

To reproduce the bug:

  1. Save one or many terms to a node.
  2. Edit the node.
  3. Set any number of terms to "None".
  4. Use "Add another one" to add a new term and save.

If you reverse this by adding your new terms first and then setting the old ones to "None", then it saves correctly.

Comments

joshua.roberson created an issue. See original summary.

deepakaryan1988’s picture

I am having a similar issue as well.
Issue scenario:
1. clone/translate/edit any content
2. Change the category term
3. Add another term
4. Save content
5. Go edit and check. Term is reverted to previous

Working fine scenario 1
1. clone/translate/edit any content
2. Add another term
3. Change first term
4. Save content
5. Go edit and check. Changed term reflects

Working fine scenario 2
1. clone/translate/edit any content
2. Change the category term
3. Dont Add another term
4. Save content
5. Go edit and check. Changed term reflects

Can anyone help me?

Though while debugging, I find out, in AppView.js which is responsible for updating Element Value.

updateElementValue: function(value, container, widgetModel) {
      var app = this;

      if (app.getSetting('multiple')) {
        value = [];
        app.collection.each(function (model) {
          var modelValue = model.get('value');
          console.log(modelValue);
          if (typeof modelValue == undefined || null == modelValue || modelValue === app.getSetting('anyValue')) {
            return;
          }
          value.push(modelValue);
        });
      }
      else {
        if (value === app.getSetting('anyValue') && widgetModel.get('level') > 0) {
          // Use value of parent widget (which is the id of the model ;)).
          value = widgetModel.get('id');
        }
      }
      // Set the updated value.
      app.$el.val(value).trigger({
        type: 'change',
        shsContainer: container,
        shsWidgetModel: widgetModel
      });
      console.log(app);
      return app;
    },

This above is not getting updated whenever we press Add Another item

That's weird, it's taking the previous item selected in above scenario.

Thanks for helping in advance.

mkindred’s picture

Title: Set none and add term ignores none » Adding new term reverts changes to existing terms
Version: 8.x-1.x-dev » 2.0.x-dev

This still seems to be an issue. The bug appears in multiple scenarios (not just when you set existing terms to 'None'), so I changed the title.

As @deepakaryan1988 mentioned, if you add a new term after changing existing terms (terms that existed prior to the current edit), then the values for the edited terms are reverted to the pre-edit values. This change happens in the background such that it looks as though your edit is OK; you find out only after you save.

Steps

Adding new term reverts changes to existing terms:

  1. edit content with existing terms saved
  2. change existing terms
  3. add a new term
  4. save
  5. changes to existing terms are lost

Saves OK if you add the new term before editing existing terms:

  1. edit content with existing terms saved
  2. add a new term
  3. change existing terms
  4. save
  5. changes to existing terms are saved

I've created a video to demonstrate the bug in a fresh D10 install: https://odysee.com/241024_drupal_shs_bug:c

jaydarnell’s picture

I'm having a much bigger problem where the add another item button doesn't work at all. I've tried the latest release for the 2.x and 3.x branch but no luck. Clicking the Add another item button causes the existing item to disappear and then reappear but no field is added for selecting additional items.

Nevermind, this appears to be a problem with my admin theme.

herve.tubaldo’s picture

Hello, any news on this issue?
I have the same problem:

  • I created a content type with a single shs field (Allowed number of values: unlimited)
  • If I create a content and select 3 terms, the first selected is not saved
  • If I select only one term, it works fine

I tested with versions 3.0.0-alpha4, 2.0.1 and 2.0.x-dev.

joseph.olstad’s picture

Status: Active » Postponed (maintainer needs more info)

Please look at your browser console for js exceptions and report them if you have some related exceptions.

It was mentioned that this could be related to your theme(s).

herve.tubaldo’s picture

Hello, thank you for your reply.

I am using the "Claro" theme and I have no errors in my browser console.

joseph.olstad’s picture

Status: Postponed (maintainer needs more info) » Needs work

Hmm @jaydarnell reported that this was an issue with his admin theme however this should work with the Claro theme.

What version of Drupal core are you using @herve.tubaldo?

herve.tubaldo’s picture

@jaydarbell had another issue, the "add another item" button didn't work at all for him, which is not my case. I have the same problem as @mkindred or the comments before.

I am using Drupal 10.3.9

mkindred’s picture

lmk if anyone needs anything further from me. While I'm probably not up to the task of creating a patch at the moment, I can test and provide more info regarding any potential theme implications, if necessary.

denix’s picture

Hello, we are using shs in webforms and no, the issue is not with the Claro theme, but as @herve.tubaldo wrote, the "add another item" button does simply not work. We are on Drupal 10.4 and module 2.0.2.

Thanks!