How to return number of widgets in panel?

JS{{
return Object.keys(@{panel_1}).length
}}

It shows 0. Am I a little bit close though?

EDIT: I think I got it!

JS{{
return @{panel_1.widgets.length}
}}
1 Like

Hi,

Where do you put this code ? In which property field ? Screenshot appreciated.

Of course!

I put it in the value of a text widget

image

Which gives you this.

buttons

If gridTemplate could be made dynamic, it would be cool to be able to adjust the flow of the buttons based on the number of widgets in a container. I know this is possible in a custom module, but there could be uses for it here in the session too.

1 Like

thanks !
When you say a text widget, you mean an html one ?

no no, just a simple text widget and place the code in the value property. I just wanted to see if the code worked first. But you could put the code into any property to be able to use it how you like.

image

Ok it works with a text widget but i must miss something with the html widget.

Edit :
we have to put into the html field BUT why not into the value field ?
the computered value is correct but the value is not displayed. could you explain me why ?

Just typing any text into value in a html widget doesn't display it.

You could put the code into the html field and format it there with css

image

and add other text to it of course

image

1 Like

so what is the aim of the value field into an html widget ?

Define the widget's value depending on other widget's values / properties using the advanced property syntax

Great question. We'll have to wait for @jean-emmanuel to clear that up for us.

As I learn more about o-s-c, I make little sessions to explore the different aspects of the program. One that I haven't figured out yet is the difference between value and value

For example a button has a value (0 or 1) but it also has a value that can be used with advanced syntaxes. I need to keep exploring this. And is this value different from value? Confusing.

get('button_2') returns the value of the button (0 or 1)
getProp('button_2','value') returns whatever is written in the 'value field'

Understanding the difference between these two values would be really great. The documentation is not that clear in this respect (or it could very well be my brain!!)

image

the widget text has an html field :slight_smile: too

and works very well as i think the html widget should work.

is there a difference between html widget and text widget ?

Just a little question : where can we use this code ? I mean we have to put between JS {{ }} somewhere ?
Edit : into the scripting zone : Scripting - Open Stage Control

But why i can't get the value :

image

i got a button_1 with a value property set to 5

wrap it in a console.log and you can see the result in the console. Then it's up to you how you use the value

nope

image

the text widget
image

and nothing in the console. An idea ?

The script is executed whenever the widget's value updates. So because the code is in the text widget, it is not updating so the script isn't run.

Put that code in a second button and hit it.

Ok thanks !
So to illustrate your thoughts about value
image

so what is the aim of the value field into an html widget ?

It's totally useless. It's just here because its a generic property, I should probably make the widget store the value internally like other widgets do.

Understanding the difference between these two values would be really great. The documentation is not that clear in this respect (or it could very well be my brain!!)

There's the value property and the widget's value (its state).

get('button_2') returns the value of the button (0 or 1)
getProp('button_2','value') returns whatever is written in the 'value field'

Exactly as you said.


is there a difference between html widget and text widget ?

Yes, the text widget displays its value with predefined layouts. (vertical, horizontal, aligned, etc). The html widget just displays html.

1 Like

Just trying to use this in a custom module.

receive('/GET',button_panel.widgets.length) is obviously incorrect.

receive('/GET','button_panel', {widgets.length}) is also incorrect but I imagine closer.

receive('/GET','button_panel', {widgets: length}) was my last attempt.

I also saw /EDIT/GET so I'm just a little confused.

/GET
Sends back a widget's value to specified target.

and

/EDIT/GET target id
Sends back a widget's data (JSON stringified object), including its children, to specified target.

are very different.,

receive('/EDIT/GET', '127.0.0.1:5555', 'button_panel')

Will make the widget send all its properties (with advanced syntax not resolved, like when reading a json session file).

So how would I translate this to a custom module? As in, I want to find out how many buttons are now in the panel, after the panel has been created?