Open tanthammar opened 4 years ago
In the listener field, at "calculated-field/resources/js/components/listener-field/FormField.vue" the following code causes the event to only affect one listener component at a time.
calculateValue: _.debounce(function() {
this.calculating = true;
Nova.request()
.post(
`/codebykyle/calculated-field/calculate/${this.resourceName}/${this.field.attribute}`,
this.field_values
)
.then(response => {
this.value = response.data.value;
this.calculating = false;
})
.catch(() => {
this.calculating = false;
});
}, 500),
Removing the _.debounce() function, and replacing the above code with this solved it for me:
calculateValue: function() {
this.calculating = true;
Nova.request()
.post(
`/fusion/calculated-field/calculate/${this.resourceName}/${this.field.attribute}`,
this.fieldValues
)
.then(response => {
this.broadcastHandler(response);
this.calculating = false;
})
.catch(() => {
this.calculating = false;
});
},
Of course, it's not ideal to modify vendor/package code. So I basically followed @codebykyle instructions here, and created my own custom package, to fix this issue myself.
@pauldstar @codebykyle
This issue can be fixed while keeping the debounce in place! This is a very useful article I used helping debug this part.
Rewrite calculate value function:
calculateValue: function () {
this.calculating = true;
Nova.request()
.post(
`/jappiewent/calculated-field-improved/calculate/${this.resourceName}/${this.field.attribute}`,
this.field_values
)
.then(response => {
this.value = response.data.value;
this.calculating = false;
})
.catch(() => {
this.calculating = false;
});
},
And add the debounce to the mounted part of your component:
mounted: function () {
this.calculateValue = _.debounce(this.calculateValue, 500).bind(this);
this.calculateValue();
},
Is it not possible to have multiple listeners on the same event?
Each of these listeners work on their own but if I add them all, only the last is updated