Hi
I'm trying to set up a dropdown that displays IdP's roles.
This is the startup script:
It works on the Client, but when I open the session in the browser, the options are not displayed.
Could someone help me?
Hi
I'm trying to set up a dropdown that displays IdP's roles.
This is the startup script:
It works on the Client, but when I open the session in the browser, the options are not displayed.
Could someone help me?
On the dropdown, props.options.
Put a binding on this with some expression, like now(10000)
and put this script in the script transform. Though I would have it just as options
instead of self.props.options
and then return
this list
Is anyone actually logged into the browser session?
I do agree that a binding with some of your code moved into a transform is better than this onStartup approach, though you don't need the now(10000)
piece. Bind against self.session.props.auth.user.roles
, then use this transform:
def transform(self, value, quality, timestamp):
roles = [{"label": role, "value": role} for role in value]
if len(roles) == 0:
placeholder = "User has no roles."
else:
placeholder = "Select role..."
self.props.placeholder.text = placeholder
return roles
Actually, I'm going to recommend moving the placeholder logic into a change script on Dropdown.props.options
. In general, it's bad practice to write to props within a transform; transforms should only be used to manipulate the binding value into some expected format.
It works
Thanks
Is there a reason it's considered bad practice to read the props in a transform?
Reading props is fine. Writing props can be troublesome for a couple of reasons.
And sometimes, quite handy. Expression bindings and expression transforms subscribe to every property you use, and will retrigger the binding for any of them.
A script transform gives you the opportunity to monitor one or more items for changes (the part before the transform, whatever it may be), then capture the values of properties and tags at just that moment, without subscribing to the latter.
For this case, isn't it more efficient to go for an onClick
event? Then, populating those Dropdown.props.options
each time you click on it.
Thinking of dropdowns as form elements, which the user may have on screen but may not even use/click on... Being subscribed to them doesn't seem very efficient.
Requiring a click doesn't work as well as you would think.
tab
-ing through inputs. If populated through an onClick Event, the field would never have the data needed.Bindings are far more efficient than you probably think. While it might be true there's a lot to do during the initial loading of a page, bindings against data which doesn't regularly update should have negligible performance impact.
Good points, thanks!