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.
<select>
<option>Through & Google</option>
<option>Through Twitter</option>
<option>Other…</option>
<option><Hi></option>
</select>
http://uniformjs.com/#example
can someone tell me what is the problem..
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 &
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.
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')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 & Two</option>
<option>One & Two</option>
</select>
The plugin gets the content as html doing elem.find(":selected").html()
Both option element will return this value when getting html: One & Two
Special characters are represented by html entities (&
for &
in our example)
and then plugin applies this result as text using spanTag.text(<html>);
So html entities do not get parsed (&
is displayed as &
)
This fiddle illustrates it.
I don't think there is a solution to that except to not use special characters like &
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With