Hiding (but keeping) fields in a block

882 views
Skip to first unread message

Andrew Stratton

unread,
Jul 18, 2017, 10:34:57 AM7/18/17
to Blockly

Hi Everyone

  I'm looking for a way to hide a part of a block - so that it can be shown/hidden depending on the expertise of the user. N.B. A mutator won't do what I want. (I think)


  Here is an example of what I'm trying to do - I have a block that shows a video - looping forever (though this isn't shown at this point). It looks like this:

When the user clicks on the ..., I can intercept the click and then run some javascript (I already have this bit working) - and next an 'expert' view opens up, showing the hidden fields within it, e.g.:

I know this looks like a mutator - but it isn't...please read on....

So - if the user chooses 'once only', then the video script will be generated to play once (I'm happy doing this).

Unlike a mutator, the user can then also hide the extra parameter, by clicking the '...', so the block looks the same as in the original picture (actually - I will give some feedback that there are 'hidden' values set).

But - it will still generate (and save) with the hidden field set to once only.

I don't think mutators allow this - since they seem to match the visible fields with the xml and generated code - i.e. the mutation changes the underlying structure - not just the visible structure (which is what I'm trying to do).

At present I think I need to loop through all the fields associated with the '...' and call setVisible( true/false ) - but is there anything like this already - before I reinvent the wheel (again)?

Cheers
  Andy

Andrew n marshall

unread,
Jul 18, 2017, 11:00:45 AM7/18/17
to blo...@googlegroups.com
Hi Andy,

Is there a reason why you don't want to store some equivalent of forever/once in the mutation tag, or allow it to dealer to your desired "once" value you at the generator level?


--
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.

Andrew Stratton

unread,
Jul 18, 2017, 5:35:10 PM7/18/17
to Blockly
Hi Andrew
  Yes - mainly that mutators are there (I believe) to allow blocks to change their 'signature' (structure) - and I'm not doing that - I just want to make things hide/show.

  I also don't want to use the mutator UI - the users were confused (my users are not programming skilled - and my project is 'hidden' programming).

  So - the pain of getting mutators to work doesn't seem worth it for the little gain - for me. Maybe if I had more time I would try mutators.

  Anyway - I have had some success with setting visible to true/false and forcing the containing block to render.  The invisible selections are still sent to/from the xml. So I seem to be fine for now.

  Thank you for your time
    Andy Stratton

Andrew n marshall

unread,
Jul 20, 2017, 2:43:55 PM7/20/17
to blo...@googlegroups.com
Hi Andrew,

The mutator UI (gear button) only shows if the addition of the mutator adds the compose() and decompose() functions. In this case, you only need to retain state, which is done with the mutationToDom() and domToMutation() methods.

You'll still need to add the event handled on the '...' button. This should invoke the necessary state change, and add or remove the inputs and fields to match.

--
Reply all
Reply to author
Forward
0 new messages