Skip to content Skip to sidebar Skip to footer

JQuery UI Encoding Nightmare

I want to be able to pass any string to the buttons text in JQuery UI. Suppose I have this string: Ajouter L'amie a la liste 'amies' The only way to actually pass this text withou

Solution 1:

To be able to use htmlentities, you'll have to use the html method when inserting the strings into the buttons, as text will literally insert the text without doing encoding of entities :

registerhtml.dialog({
    modal: true,
    title: 'My Dialog Title',
    resizable: false,
    buttons: [
        {
            html: 'Ajouter L'amie a la liste "amies"',
            click: function(){
                // Do something important
                $(this).dialog('close');
            }
        },
        {
            html: 'Cancel',
            click: function() {
                $(this).dialog('close');
            }
        }
    ]
});

FIDDLE


Solution 2:

Depending if you use ' or " for your string, escape all accournces of ' ör " in the string with a \

Example:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Demo</title>
        <script src="jquery-1.8.2.min.js"></script>
        <script src="jquery-ui-1.9.0.custom.min.js"></script>
        <link href="jQueryUI_css/ui-lightness/jquery-ui-1.8.24.custom.css" rel="stylesheet" />
        <script>
            $(function(){

                //using ' to define a string
                var text = 'Ajouter L\'amie a la liste "amies"'
                $('div').text(text).button();

                //using " to define a string
                var text2 = "Ajouter L'amie a la liste \"amies\"";
                $('button').text(text).button();
            });
        </script>
    </head>
    <body>
    <div></div>
    <button></button>
    </body>
</html>

Post a Comment for "JQuery UI Encoding Nightmare"