Changing a Tag value with a component - Perspective

Hi everyone,

I’m trying to related the value of my dropdown to a tag. So, if I choose the first item of my dropdown, my tag value would be 0 and if I choose the second item of my dropdown, my tag value would be 1. I did a OnChange script, it work when I do preview mode, but doesn’t when I’m in a browser.

Thank you all for your help.

Have you considered using a bidirectional tag binding?

https://docs.inductiveautomation.com/display/DOC81/Tag+Bindings+in+Perspective

1 Like

Thanks, it work!
But it takes like 5 seconds to my label to set. In this 5s, labels are switching rapidly between English and French, do you know why?

I don’t know for sure. Did you make sure to remove your tag change script when you introduced the binding?

Yes I did

What labels ? Are they displaying data related to the tag you’re changing ?
How do you handle translation - is it a global translation, or are you using the translate() expression function ?

They are simple label components. I enter all my translation into the Translation Manager and with my dropdown I change the session.props.locale value between “fr” and “en-US”.

So the dropdown is used to select the display language, or is that a different dropdown ?
If that’s the dropdown you were talking about, what’s that tag you are trying to modify supposed to do ?

I only have one dropdown and I change the value of a memory tag (with bidirectional option).
image

This memory tag is relate in a script in the binding of locale (in session/props/locale).

Why don’t you just change the session.props.locale ? That’s what session properties are for, changing a tag will change the language in all clients. And it frankly makes things more complicated than they have to be…
Or does the tag have some other use ?

I’d suggest you bind your dropdown directly to session.props.locale, and let it handle one and only one thing.
Also, you might want to use fr-FR (or fr-CA, fr-BE, fr-CH…) instead of just fr.

I can also help you in french through private messages if you’d like, I’d rather keep the public forums english only.

Thank you, it worked! I didn’t use that binding because I didn’t know I could :sweat_smile:

You’re welcome !
Do change that ‘fr’ to ‘fr-FR’ though.

What does it change?

That’s how we write locales. It makes it easy to see that it is indeed a locale, and some things need it to be in that format in order to parse it correctly.
In your case it might not change anything, but complying to conventions when writing code is a good habit to have.

1 Like