How to "validate block"?

68 views
Skip to first unread message

Naresh Chaudhari

unread,
Feb 23, 2021, 6:27:22 AM2/23/21
to Blockly
Hi All, I'm developing an application where there is a number of blocks the user has to be used in sequence. If any blocks are missing or the user has not added then it should throw an error message in the popup. 

For example:
There are five blocks: start, system_import, application_import, business_logic, end except for "business_logic" block other blocks are mandatory block which user has to use.
If the user has added the first two blocks and the last two blocks in the workspace. and trying to validate the code it should throw an error as "application_import" is missing.

(Here "Validate code" is a button that checks and any blocks are missing or not. If any blocks are missing then it will throw a message with a missing block name otherwise it will display some other message(No missing blocks))

Thanks in advance.

Beka Westberg

unread,
Feb 23, 2021, 3:52:25 PM2/23/21
to blo...@googlegroups.com
Hi! Sounds like an interesting project. Is there some part of the implementation you're getting stuck on?

Best wishes,
--Beka

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/ceb23df0-326c-45da-8cac-33d72fc1a794n%40googlegroups.com.

Naresh Chaudhari

unread,
Feb 24, 2021, 2:05:01 AM2/24/21
to Blockly

Hello,
No, I've not stuck anywhere but the thing is like.... If any block is missing the application should not run and display a message. When I click on Validate Code it will check that the user has added mandatory blocks or not? 

Beka Westberg

unread,
Feb 24, 2021, 5:47:06 PM2/24/21
to blo...@googlegroups.com
> When I click on Validate Code it will check that the user has added mandatory blocks or not? 

Hmm, clicking on a "Validate Code" button will only validate the code if the button has a listener attached that has logic to validate the code.

If you want to validate code some helpful functions/properties you might want to look into are:

Best =)
--Beka

Naresh Chaudhari

unread,
Mar 3, 2021, 6:24:42 AM3/3/21
to blo...@googlegroups.com
Thanks Beka!

Using workspace.getAllBlocks method i fixed the issues and it is working fine now. 

Thanks again for your help

Reply all
Reply to author
Forward
0 new messages