Search code examples
javascriptjquerylistviewcharacter-encodinguniform

need help in jquery unformjs select menu '&' character encoding


I am using uniformjs form controls which are working except the listmenu. When i add '&' symbol (&) inthe list menu, it renders correctly, but problem is coming when i change the value to different value and select again the value which has & symbol it renders as & instead '&' symbol in the list menu. enter image description here

enter image description here

<select>
<option>Through &amp; Google</option>
<option>Through Twitter</option>
<option>Other&hellip;</option>         
<option>&lt;Hi&gt;</option>
</select>

http://uniformjs.com/#example

can someone tell me what is the problem..


Solution

  • I think the problem might come from this line (source - line 185):

    spanTag.text(elem.find(":selected").html());
    

    If you have the following html:

    <select>
        <option>One &amp; Two</option>
        <option>One & Two</option>
    </select>
    
    1. The plugin gets the content as html doing elem.find(":selected").html()

      Both option element will return this value when getting html: One &amp; Two Special characters are represented by html entities (&amp;for & in our example)

    2. and then plugin applies this result as text using spanTag.text(<html>);

      So html entities do not get parsed (&amp; is displayed as &amp;)

    This fiddle illustrates it.

    I don't think there is a solution to that except to not use special characters like &...