need help in jquery unformjs select menu '&' character encoding
Asked Answered
M

3

5

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..

Mckown answered 11/1, 2012 at 7:31 Comment(2)
Is the ampersand represrnted as an entity in the markup ? <option>One &amp; Two</option> ?Umpteen
@Didier G. I did tried both ways <option>One &amp; Two</option> and <option>One & Two</option>, but both the problem still retains..Mckown
U
3

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 &...

Umpteen answered 11/1, 2012 at 10:10 Comment(0)
L
4

According to Didler, why not modify the uniformjs a little bit?

I have met the same scenario recently, and thanks Didler to point out the exact line which saves me heaps of time to locate the place.

In my case, I have a select with value consists of special characters, such as:

<option>aaa</option>
<option><a>bbb<br>ddd<hr>ccc</option>

So that I modify the code in line 185 to:

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

which solves the problem that when render the value it is in a correct shape.

In op's scenario, I'm not sure which server side language you are using, but definitely there is a way to escape the text within option before generating the html page so that there is no &amp; in your html but the character itself. I'm using Java so that I can simply use JSTL <c:out value="${******}"/> to put the value in the option tag.

Lowly answered 29/2, 2012 at 3:1 Comment(1)
am using cold fusion for generating this optionsMckown
C
4

There's a pull request (130) that updates 4 lines of code (lines 173, 185, 212, and 569) so that instead of using .html() they use .text(). The two later pull requests I saw don't seem to update all 4 lines.

If you wish to update the minified version as well, you can search for these two snippets:

  • l.html(n.html() (x1 - change second instance of 'html')
  • :selected").html( (x3 - change only instance of 'html')
Children answered 13/7, 2012 at 15:30 Comment(0)
U
3

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 &...

Umpteen answered 11/1, 2012 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.