Value of property before binding is executed in perspective

Hi,

I'm trying to set a default value for a property before the binding is executed in Perspective.

Here's the situation:

I have a button whose text is bound to a custom property called "datetime" The "datetime" value is only available after 500 ms, which is the time it takes for the binding expression to evaluate in the view.

During the initial 0-500 ms period, the button displays the text "button," which is not what I want. I would prefer it to show something like "loading" until the actual date is available.

I've tried using a persistent property, but if I save my project while a date is shown, that date becomes the default value.

Do you have any suggestions on how to resolve this issue?

@pturmel do you have any idea, please ?

Set the property back to transient, and try something like coalesce(path.to.property, default).
I'd expect the prop to be null before the binding evaluates.

But... 500ms ? Where does the data come from ?

What do you mean by "set the property back to transient" ?

I tried the function coalesce(), but the result is always the same.

500ms it's the approximate time to evaluate binding expression, before evaluation the button text shows "button".

Transient is the opposite of persistent. So, make it not persistent, like it was before.
Without this, The property won't have a value, so you should be able to use coalesce.

My bindings never took 500ms to evaluate. Hence my question: What is it evaluating ?

I created a startup event on my view:

I set custom property of my button named "datetime" to the value returned by the function (simple function, does some string calculations).

Than, I bind the button text value with this expression.

When I load the view the button text shows button for very short time (it approximately 500ms).

Get rid of the startup script and use a binding on the datetime property.
The binding would look something like this:

runScript(getFirstShiftStartDateTime, 0)

If it takes 500ms to load, that's because your script takes 500ms to execute.
Are you doing I/O operations in it ?
Can you show the whole script ?

Here is the whole script, added a line to edit the text at start, the button text appears although for approximately 300ms then "Hiiiii" appears in a second time.

I meant the settings.getFirstShiftStartDateTime function's code.

I really mean it: Use bindings, not init scripts. These scripts go in the opposite direction of Ignition's philosophy.

3 Likes

Especially for any "open" script. Ignition caches all kinds of things and may not run such events when you think it should. Use bindings.

I tried to do what you suggested but result is always the same, it seems like it takes time to run binding expression.




I tried using this binding but it works the same, the problem is always there.

That's not how coalesce works. dateFormat will never return a null, so coalesce won't do anything.
try this instead:

if (isNull({this.custom.datetime}),
  "loading...",
  dateFormat({this.custom.datetime}, 'dd-MM hh:mm')
)

I suggest you read this:

edit: that shift script looks funky to me. It seems dates are strings, but you're getting them from built-in features. There's something weird here.

edit again:
yep they're strings:
image
I'm not sure what it's supposed to represent, and there's no details in the docs

The binding it self takes time to execute when a view is loaded see the video:

The problem is that button component shows text "button" by default before the binding is evaluated when text is not persistante.

Edited:

If you just try add button anywhere and set text property to not persistante, the text that will be shown is "Button" by default and i think that it is a bug.

1 Like

You should just paste/attach images/gifs/videos directly into your posts rather than uploading them to other sites that will most likely delete them

Edit: I just realised it was 35MB for a gif using dithering??
Scratch that, use a proper screen recorder like ScreenToGif. That video should be 1MB max

3 Likes

Why would the text of a button not be persitant? Just because it's behavior is unexpected by you, doesn't mean that it's unexpected behavior for the developers.

I understand what you are saying the issue is, but what I am interested in is why? Why are you changing the text on a button?

1 Like

It's a button which will display the start date of production of my machine and as i click i will get the previous date and so on. At the view startup, the button displays "button" before its gets the right date.

I understand that it’s a button that is displaying a date. That’s more What the button is doing not why.

The text could just as easily say “Previous Date” and be persistent and then your problem presumably goes away. But without understanding why you’re changing the text on the button rather than in a datetime component, we can’t really suggest any other work around than “deal with it”.

I don’t think this is a bug, I just think the default value is “Button” when the value is null.

At the start-up for every non-persistent binding the value will be null.

1 Like

yes i tried your solution, but i faced new issue which has the same cause, if i want to disable the button when the date is after now, i will get the button enabled before the expression executes.