Fomantic-ui: [Dropdown] Values are parsed incorrectly when they contain <, ≤, etc

Created on 5 Dec 2019  Â·  4Comments  Â·  Source: fomantic/Fomantic-UI

Bug Report

Steps to reproduce

  1. Create a dropdown
  2. Set its values to <, >, ≤, and ≥
  3. Get values and inspect the result

Expected result

Get the values for < and company

Actual result

Get &;amp;amp;amp;lt; and company. The number of &amp; might be related to number of selected values?

Testcase

https://jsfiddle.net/4cqtnf0d/

Screenshot (when possible)

image

Version

2.8.2

lanjavascript typbug

All 4 comments

EDIT: Read next comment, this does work in some cases but there is another case I had not found until after I had written this one.

If anyone needs a workaround to fix this, I made a little function that will decode the values:

let decodeEntity = (text, iterations) => {
  iterations = iterations || 10;
  for(let i = 0; i < iterations; i++) {
    text = $("<div/>").html(text).text();
  }
  return text;
}

You pass it the text with HTML entities in it and the number of iterations. The second argument is the amount of times to decode the text, since the values are encoded every change it seems you have to do it the amount of changes the dropdown has had, since the old values will not be removed. The values array is still kinda buggy.

let decode_iterations = 0;
$('.ui.dropdown').dropdown({
  onChange: val => {
    decode_iterations++;
  }
});
let values = $('.ui.dropdown').dropdown('get values').map(val => decodeEntity(val, decode_iterations));
console.log(values);

jsfiddle example

I think this is also messing with the changing logic, when a value is removed it can't find any match in the values for 1< so it doesn't remove the value in the array for 1&amp;amp;amp;amp;amp;amp;amp;amp;lt;. You can see that by unselecting elements in the dropdown in this fiddle.

image

This also highlights that the elements are further encoded, so I will modify the above decoding function to more accurately decode based on the number of changes, even if there is a larger problem relating to the values not being removed.

I would say that using $(".ui.dropdown a[data-value").toArray().map(el => $(el).data("value"); to get the values might be safer until this is fixed.

Fixed by #1210 . See your adjusted jsfiddle here https://jsfiddle.net/kjqoa89e/

@GammaGames I also fixed the remove label issue now
See your adjusted jsfiddle here https://jsfiddle.net/vckzmxaf/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hammy2899 picture hammy2899  Â·  5Comments

neokio picture neokio  Â·  4Comments

davekc picture davekc  Â·  4Comments

Puspendert picture Puspendert  Â·  3Comments

hajanajubudeen88 picture hajanajubudeen88  Â·  5Comments