set text field non editable

24 views
Skip to first unread message

Zeeshan

unread,
Nov 28, 2022, 2:07:53 AM11/28/22
to Blockly
Hi all,
I want to make the text field non-editable, wanted to show my own text. is there any way I can do that?

Neil Fraser

unread,
Nov 28, 2022, 5:46:27 AM11/28/22
to blo...@googlegroups.com
There are a few options.

The simplest option is to use a label.  Your block definition:
{
'type': 'field_label',
'class': 'notEditable',
'text': 'Hello',
},
And you can style it with CSS (note these are SVG styles, not HTML styles):
<style>
.notEditable {
fill: #f8f !important;
}
</style>
Result:
Screen Shot 2022-11-28 at 11.35.00.png
Unfortunately, I don't see a way to get the rounded rectangle behind the text using this option.

If your content isn't dynamic, another option is to use an image.  Your block definiton:
{
'type': 'field_image',
'src': 'static_image.png',
'height': 30,
'width': 50,
},
Result:
Screen Shot 2022-11-28 at 11.40.17.png

Yet another option is to subclass the editable text field, and override its showEditor_ with an empty function.


Am Mo., 28. Nov. 2022 um 08:07 Uhr schrieb Zeeshan <zeeshanb...@gmail.com>:
Hi all,
I want to make the text field non-editable, wanted to show my own text. is there any way I can do that?

--
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/b095ae66-38d7-4f28-8edc-86f1eab4688bn%40googlegroups.com.


--
Neil Fraser, Switzerland
https://neil.fraser.name
Reply all
Reply to author
Forward
0 new messages