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

Defining buttons as array issue #39

Closed martinbabic closed 10 years ago

martinbabic commented 10 years ago

I've tried defining buttons as array (latest stable version - v5.2.4) by copy&paste of book example:

prompt("Would you like to proceed?", { buttons: [ { title: "Yes, I'm Sure", value: true }, { title: "No, Abort", value: false } ] });

But I get additional 20 or so buttons, 'each', 'eachSlice'...:

impromptu-buttons-as-array

Using buttons in 'normal' way ("Yes, I'm Sure": true) works normally. No js errors are thrown in Firebug. jQuery version is 1.11.1.

Any ideas?

trentrichardson commented 10 years ago

Looks like it needs to verify it is a property of the object in impromptu (it is a bug). I will be making some updates tonight and will fix it. On Aug 31, 2014 8:23 AM, "martinbabic" notifications@github.com wrote:

I've tried defining buttons as array (latest stable version - v5.2.4) by copy&paste of book example:

prompt("Would you like to proceed?", { buttons: [ { title: "Yes, I'm Sure", value: true }, { title: "No, Abort", value: false } ] });

But I get additional 20 or so buttons, 'each', 'eachSlice'...:

[image: impromptu-buttons-as-array] https://cloud.githubusercontent.com/assets/2845993/4101874/91f0bbce-3109-11e4-8359-0bb741916ea4.png

Using buttons in 'normal' way ("Yes, I'm Sure": true) works normally. No js errors are thrown in Firebug. jQuery version is 1.11.1.

Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/trentrichardson/jQuery-Impromptu/issues/39.

trentrichardson commented 10 years ago

@martinbabic I've tried running the example with arrays of buttons from the book in Firefox and they work fine, as well as the spec runner for the tests.

However looking over the code I was not using Object.hasOwnProperty() to verify the properties (this was what I suspected, but I don't know that this is necessarily the issue). I restructured the button generation a bit for this, so it may fix your issue.

If this does not fix your issue (well, even if it does fix) I do have a question. These extra buttons look to be utility/helper functions that were probably added to the Array object (they're not native js Array functions, but their names sound like array functions).

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

Are you including some other library adding these functions (Array.each, Array.any, etc)? I suspect they could be implemented wrong as they are iterable which should not happen on an array. You might try running a clean example of just jquery and impromptu scripts included and your copy/paste from the book example to see if you still get this issue.

martinbabic commented 10 years ago

@trentrichardson: Seems you're correct, when trying impromptu button array outside Magento ecosystem everything works as intended so it probably is some issue related to other js libraries such as prototype, I'll try your fix tomorrow and let you know if it works. On Aug 31, 2014 10:33 PM, "Trent Richardson" notifications@github.com wrote:

@martinbabic https://github.com/martinbabic I've tried running the example with arrays of buttons from the book in Firefox and they work fine, as well as the spec runner for the tests.

However looking over the code I was not using Object.hasOwnProperty() to verify the properties (this was what I suspected, but I don't know that this is necessarily the issue). I restructured the button generation a bit for this, so it may fix your issue.

If this does not fix your issue (well, even if it does fix) I do have a question. These extra buttons look to be utility/helper functions that were probably added to the Array object (they're not native js Array functions, but their names sound like array functions).

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

Are you including some other library adding these functions (Array.each, Array.any, etc)? I suspect they could be implemented wrong as they are iterable which should not happen on an array. You might try running a clean example of just jquery and impromptu scripts included and your copy/paste from the book example to see if you still get this issue.

— Reply to this email directly or view it on GitHub https://github.com/trentrichardson/jQuery-Impromptu/issues/39#issuecomment-54000373 .