Alternative to Javascript Alert

544 views
Skip to first unread message

Chris Johnson

unread,
Oct 9, 2016, 5:18:15 PM10/9/16
to Blockly
I've got a Blockly application that I use with elementary and middle schoolers. I occasionally pop up alerts or prompts using Javascript, as does Blockly itself, such as on a variable rename or a save-as. In addition to alerting and prompting, decent browsers provide a checkbox that allows the user to suppress future dialogs. My students will sometimes check it without thinking. But this cripples some of the features of my application. I'm considering overriding the builtin functions with JQuery UI replacements, but I wanted to hear what others are doing first.

Have you encountered this situation? What do you do to handle the inherent vulnerability of Javascript's alert/prompt? 

Thanks.

- Chris

Neil Fraser

unread,
Oct 9, 2016, 5:22:38 PM10/9/16
to blo...@googlegroups.com
Absolutely, the print and prompt blocks are intended as minimal I/O blocks that developers can use to get started.  No professional Blockly application uses them.  But conversely, they work out of the box without any extra libraries.

Go ahead and override those blocks.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Chris Johnson

unread,
Oct 10, 2016, 7:37:29 AM10/10/16
to Blockly
Thanks, Neil. My question wasn't actually about the blocks, but the underlying Javascript functions. I guess it really wasn't a question specific to Blockly. Still, I think your answer applies.

- Chris

Chris Johnson

unread,
Oct 10, 2016, 1:32:01 PM10/10/16
to Blockly, ro...@neil.fraser.name
Looking into this further, it seems that a blocking window.confirm is assumed in Blockly.Workspace.deleteVariable and BlocklyWorkspaceSvg.showContextMenu_. And a blocking window.prompt is assumed in Blockly.Variables.promptName and Blockly.FieldTextInput.prototype.showEditor_. Replacing these blocking calls is impossible, is it not, without introducing non-blocking behaviors?

- Chris
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Andrew n marshall

unread,
Oct 10, 2016, 11:27:35 PM10/10/16
to blo...@googlegroups.com

As a Blockly user, I agree they should be replaced. Browser dialogs are annoying.

We could easily wrap alert and prompt with  callback driven versions under the Blockly namespace. Then, app developers could replace those functions with versions that are more fitting for their UI.

Chris, would this fit your needs?


To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.

Chris Johnson

unread,
Oct 11, 2016, 6:36:13 AM10/11/16
to Blockly
Yes, for all three of alert, confirm, and prompt. I'd wager that the severity of this exceeds annoyance, often leading to significant disruption. It seems that everyone using core Blockly is subject to this potential dialog suppression.

- Chris

Rachel Fenichel

unread,
Oct 17, 2016, 4:24:18 PM10/17/16
to Blockly
I'm with Neil on this one: using alert/confirm/prompt for the basic blocks is worthwhile because you can use it immediately, and developers should be changing them to something nicer that fits in with their particular style.  Developers can easily change what those blocks do, as they would change any of their own blocks, so I think that's a non-issue.

The alert/confirm/prompt calls in the variables are more of a problem, since that's buried in the core code.  I would be open to making those callbacks that the developer can modify.

Carlos Pereira

unread,
Oct 18, 2016, 7:24:04 PM10/18/16
to Blockly
Hi Rachel,

I haven't been able to keep up with the latest changes in Blockly for a few months, but I was under the impression that (at least some of) the window alert and prompt used for variable name management was removed when the variable typing was reworked during the summer? If I remember correctly there was a PR by Markus when he was working on Coding with Chrome that addressed this specific issue.

Regards,
Carlos

Rachel Fenichel

unread,
Oct 19, 2016, 2:16:53 PM10/19/16
to Blockly
Hi Carlos,

I didn't consider this as an issue when I was working on variables, so there are at least two places in the new variables code that use window.prompt/alert: https://github.com/google/blockly/blob/master/core/variables.js#L260 and https://github.com/google/blockly/blob/master/core/variables.js#L239.

I guess you're probably referring to this PR: https://github.com/google/blockly/pull/396, which I'll take another look at now that the new variable stuff has landed.

Rachel

Carlos Pereira

unread,
Oct 19, 2016, 6:26:17 PM10/19/16
to Blockly
Hi Rachel,

Yeah, that's the PR and the two cases I was referring to, thanks for tracking it down and having a look :)

Rachel Fenichel

unread,
Oct 20, 2016, 8:27:42 PM10/20/16
to Blockly

Chris Johnson

unread,
Oct 20, 2016, 9:25:35 PM10/20/16
to Blockly
You people are great. I will check it out.

Rachel Fenichel

unread,
Oct 20, 2016, 9:30:59 PM10/20/16
to Blockly
I think Andrew's been bothered by this for a bit :)

Thanks also to Markus for his original PR on this, though it came in when we had too much churn on variables to accept it.

Andrew n marshall

unread,
Oct 20, 2016, 9:42:21 PM10/20/16
to blo...@googlegroups.com

I didn't even know about Markus's PR until this morning, or notice yesterday's chatter about this. It was just an itch I needed to scratch.

Happy to help. (Now back into my Android corner.)


To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages