Taxonomy Autocomplete Field not saving state correctly (with Fixes)



A. When an autocomplete taxonomy field has the same text value for the term, and you add/remove one of those terms from the autocomplete box, both terms will be affected by the change, not just the one you selected.

Reason for problem A: the jQuery selection does not include the term id, only the term text.

B. When you add a taxonomy term, then remove it, then add that same term again (all without publishing/saving), then finally publish it, the term will not be saved.

Reason for problem B: the jQuery attr method is used, when the prop method is required (see http://stackoverflow.com/questions/15266533/jquery-attrchecked-checked-works-only-once)

Recreate A:
  1. Create a taxonomy called "Test"
  2. Add a terms to it, called "My Test Term".
  3. Add another term, select "My Test Term" as the parent term, and call it "My Test Term" also.
  4. Edit any content definition, e.g. page.
  5. Add a taxonomy field called "MyTaxy" and Save.
  6. Edit the field, and select your "Test" Taxonomy, and choose "Enable Autocomplete", and Save.
  7. Create a new content item for that content definition, e.g. new page
  8. Fill in all required fields, except the taxonomy field autocomplete box.
  9. Add a SINGLE "My Test Term" to the autocomplete box.
  10. Publish the item.
  11. Note that when the page is re-displayed, the autocomplete box now shows BOTH terms.
Recreate B:

Having done the steps in A.
  1. Create a new content item for that content definition, e.g. new page
  2. Add a term.
  3. Remove the same term.
  4. Add the same term.
  5. Publish the item.
  6. Add the other required fields and publish.
  7. Note that the term is missing when the page is re-displayed.
Fix A:

In the file admin-taxonomy-tags.js:

Replace the line:
var $termCheckbox = $("input[data-term-identity='" + tag.label.toLowerCase() + "']", $terms);
var $termCheckbox = $("input[data-term-identity='" + tag.label.toLowerCase() + "']", $terms).filter(function () {
    return $(this).siblings("input[value='" + tag.value + "']").length;
Fix B:

In the same file as Fix A:

Replace the line:
$termCheckbox.attr("checked", action == "added");
$termCheckbox.prop("checked", action == "added");


sebastienros wrote Oct 24, 2013 at 7:25 PM

Fixed in changeset 5d06964983eaa0d0edcacbb51e13c9860698a1ab