cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Custom Widget Property Update Error

andrewbarlow1
Participant
0 Kudos

Hello SAP Community,

I was after a steer on where I am going wrong with a custom widget I am developing?

The actual widget works great however if I have multiple instances of it on the screen when I set the property of one of the instances it affects all instances.

All the widget does is create a div and populate it every second with the time so it's like a real-time clock, however I have added a couple of properties which are set from the builder *.js file of "offset" and "dst" to allow the user from the designer to 1. Set any offset (e.g +5 to give me the time in India) and 2. any Daylight Saving Time (e.g. +1 to give me BST).

As mentioned the widget works as expected until I change the value in the designer which bleeds into all instances of the control instead of just the one I am updating. I have attached the code to see if somebody could help me with this...

timejson.txttime-bpsjs.txttimejs.txt

Accepted Solutions (1)

Accepted Solutions (1)

vishalakshmi
Contributor

In your provided code, the issue you're facing where changes to properties affect all instances of your custom widget occurs because you are using global variables dst and offset to store the values of these properties. These global variables are shared across all instances of your custom element, which is why changing one instance's properties affects all instances.

To fix this issue, you should store the dst and offset properties as instance-specific properties within your custom element.

Thanks,

Lakshmi.

andrewbarlow1
Participant
0 Kudos

Lakshmi - first of all thank you for looking at the code. I will change this and see if it fixes it. I really appreciate the help.

andrewbarlow1
Participant
0 Kudos

Thank you Lakshmi - you were correct. I changed those 2 global variables (dst and offset) for the following in the constructor.

this._dst;

this._offset;

Have a great day!

Answers (0)