[Perspective] Bidirectional bindings and default values

Hello.

I think I have stucked on some basic stuff, but I have not found clear explanation.

So, I have a View, which is my template, let’s call it InputTemplate. Template has a Label and TextField inside. text property of TextField is bidirectionaly binded to View parameter called value (which is bidirectional, also). The goal is, when I change the parameter, value inside TextField also change, and when I type in something to TextField directly, parameter will also change. This is clear.

Then, I am putting this InputTemplate into other View, called ParentView. I bind bidirectionaly value parameter of a template to the session parameter. The goal here is to store the value from InputTemplate inside session. I hope, this is clear.

Now, when I open a ParentView, which value I will see in my InputTemplate text field? What I have faced:

  1. Sometimes default value of InputTemplate goes to session parameter
  2. Sometimes session parameter goes to InputTemplate

Can I somehow control this behaviour, e.g. Session wins? Maybe there is other way of handling such case?

Best regards,
Maciej

why dont you directly bind to the session?

Hello @victordcq and thanks for answer.

The idea of having such template with parameters is to be able to reuse it many times and be able to bind its parameters to different session parameters. It is just a simple example, in real it is more complex and has more components and logic inside :slight_smile:

i dont think its gonna work that easily like that… the order of bindings/components is not very predicatable… does it still happen if you dont have any default values in any of the templates?

You’re better off passing in the path to the session prop instead of binding it to the value parameter. Of course it was always easier in Vision to do this as you would use client tags which you could then bidirectionally bind to within the text field. In Perspective however you’ll have to use a change value event handler on the text field as well as an expression binding using property('self.session.custom.' + {self.view.param.propertyPath})

At least that’s what I’m thinking off the top of my head

2 Likes

Thank you very much.

This is something what I need:

property('self.session.custom.' + {self.view.param.propertyPath})