- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 06:22 AM
Is there a way to calculate the total for this? The quantity will still need to be multiplied based on the price per size of the drink and I wanted to store the total into another variable that is not inside the multi-row variable set.
Is there also a way so that every time they click add It'll update the total variable outside of the MRVS
Solved! Go to Solution.
- Labels:
-
Studio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2022 02:34 AM
Thread closed:
Please refer to this link for displaying the data: How to display data from a client script to an HTML widget and display its value in a text field.
In short, for the calculation and displaying of data. I used a custom with label variable and created a widget
with the following client script:
api.controller = function($scope) {
/* widget controller */
var c = this;
$scope.$watch(function() {
//Internal Name of Variable Set 'item_details'
return $scope.page.g_form.getValue('choose_your_drink_s');
}, function(value) {
if (value) {
var mrvsData = JSON.parse(value.replace(/'/g, ''));
console.log(value);
var totalCost = 0;
for (var i = 0; i < mrvsData.length; i++) {
var mrvs = mrvsData[i];
totalCost += parseFloat(mrvs.pricePerSize) * parseFloat(mrvs.quantity);
alert('Calculating: ' + totalCost + ' for --> ' + mrvs.pricePerSize);
}
//Set Value in the Total Cost
alert(totalCost);
c.data.cost = totalCost;
$scope.page.g_form.setValue('total_amount',totalCost);
alert(c.data.cost);
}
});
};
and HTML:
<div>
<input type="text" value ={{c.data.cost}} readonly>
</div>
To achieve this:
~Melvin B.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 10:13 PM
Hi
To show the total sum use the variable type Single Line Text instead of Custom with Label. Also, confirm if you are not receiving alerts as well.
Thanks,
Kartik Sethi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 10:19 PM
Hello Kartik,
I wanted to use a single line text type but I have created a custom widget for handling the calculation as per what others have said. How may I connect the widget to a single line text type? Is there a way for it? Also I have confirmed that the script works as the alerts are working and giving the correct values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 10:42 PM
Hi
As per LOC#21, you should be able to set the value. Are you not getting the value? Also, confirm if you are getting the alert.
Thanks,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 10:49 PM
Hello Kartik,
It is not setting the value on a single line text field nor a custom / custom mlabel variable, the alert works only if I use the custom label and connecting the widget to it.
Here is the script of the widget.
Since I was basing it on the thread you were able to give an answer. I would just like to ask a question if the process is still the same? How was this achieved?
I tried it on a single text field but unfortunately it still won't show the value nor are the alerts showing up.
I apologize for the inconvenience. . .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2022 02:34 AM
Thread closed:
Please refer to this link for displaying the data: How to display data from a client script to an HTML widget and display its value in a text field.
In short, for the calculation and displaying of data. I used a custom with label variable and created a widget
with the following client script:
api.controller = function($scope) {
/* widget controller */
var c = this;
$scope.$watch(function() {
//Internal Name of Variable Set 'item_details'
return $scope.page.g_form.getValue('choose_your_drink_s');
}, function(value) {
if (value) {
var mrvsData = JSON.parse(value.replace(/'/g, ''));
console.log(value);
var totalCost = 0;
for (var i = 0; i < mrvsData.length; i++) {
var mrvs = mrvsData[i];
totalCost += parseFloat(mrvs.pricePerSize) * parseFloat(mrvs.quantity);
alert('Calculating: ' + totalCost + ' for --> ' + mrvs.pricePerSize);
}
//Set Value in the Total Cost
alert(totalCost);
c.data.cost = totalCost;
$scope.page.g_form.setValue('total_amount',totalCost);
alert(c.data.cost);
}
});
};
and HTML:
<div>
<input type="text" value ={{c.data.cost}} readonly>
</div>
To achieve this:
~Melvin B.