trentrichardson / jQuery-Impromptu

An extention to help provide a more pleasant way to spontaneously prompt a user for input.
http://trentrichardson.com/Impromptu/
MIT License
327 stars 144 forks source link

Buttons with HTML characters not created correctly #66

Open ajwaddell opened 9 years ago

ajwaddell commented 9 years ago

The issue I am having is when a HTML character is within the button text the button is not created correctly because the button tag is closed prematurely.

I have created a jsFiddle to recreate the issue. http://jsfiddle.net/ajw89/byoasc15/3/

I have also tried running htmlentities() prior to passing the text into impromptu. This fixes the display issue, but the button click is not recognised. This is because the impromptu internal button object looks like the image below and when it is comparing the button.text() value "B<C" it doesn't match, so it won't know the button was clicked.

image

Is this a bug or is there a way to get around this issue?

trentrichardson commented 9 years ago

@ajwaddell Sorry for the delay, this slipped through the inbox. You can pass an array of objects also like so:

$.prompt('hello world', {
    buttons: [
        { title: 'text', value: 123 },
        { title: 'text', value: 456 }
    ]
});
ajwaddell commented 9 years ago

I have tried passing an array of objects like you said. It fixes the '<' issue I was having. Unfortunately if the button text contains a single quote. The button clicked is set to 'undefined'.

I have updated the jsFiddle to demonstrate this. http://jsfiddle.net/ajw89/6vbenuwm/1/

trentrichardson commented 9 years ago

Thanks for creating the jsfiddle, that helps me see the issue directly. It does seem to be a bug. I will try to take a look into resolving it. I will say however that you can swap that ' with an actual ' and seems to work, although I don't have all browsers available to test on at the moment.