Field values influence eachother

I’m creating new fields for opening times. However, the field influence eachother.

Actually the first field should read Tuesday (received correctly from options), but it’s overwritten by the next field… Also changing opening/closing time, change all fields.

It might have to do with: this.on('bindingupdated'
However I also have the same issues with the checkbox (onchange function).

It’s based on the date-range field of @raffaelj
I studied several default fields (in modules folder) and on Github from @raffaelj

I’m wondering what do I overlook?

Gist with the tag file:

I tested your gist, added multiple fields of type dayopeningtime and it worked without any changes… Which browser do you use? Mine is Firefox 81.0.1 (64-bit) on openSUSE Tumbleweed.

And which cockpit version do you use? I use the latest next branch.

1 Like

Hey there,

i quickly scanned the code and it might have something to with using the same day twice, in your example it’s wednesday. Also see line 85.

Furthermore i have noticed, that the script isn’t scoped in any way. I don’t know how these .tag files are getting rendered in the end and how they play together, but from a javascript perspective all your variables are now referencing the global window object with “this”, meaning that everything, you declare on “this” actually declares it on the window object, which can lead to massive unexpected behaviour.

To fix this, you could wrap your code in an IFEE ->

(function () {
your script goes here

But again, i’m not sure how tags are getting rendered in the end or if any scripts automatically scope scripts in your tags.

1 Like

@raffaelj Thanks for checking and testing this so quick. I just noticed it was a very messy error. I gave the field the same name (so both were called “day”) in the collection.

@nino1337 I assume the tag files are scoped internally. The usage of “this” is done in all .tag files, so I think it’s intended. The inner workings of CockpitCMS are still a bit a blackbox for me. Riot documentation is also not so great.

By reverse engineering the examples of others you can accomplish a lot. Thanks for sharing you work @raffaelj and the forum support.