Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Example that can be used to capture MRVS values, including when a record is deleted — a scenario for which there is currently no native event for row deletion.
- */
- //CATALOG SCRIPT ONLOAD
- function onLoad() {
- var scope = (this && this.angular ? this.angular : angular).element((this && this.document ? this.document : document).body).scope();
- // avoids registering twice
- if (scope._refundDereg) {
- return;
- }
- var refundListener = function(evt, parms) {
- if (parms.field.name == 'vs_refund') {
- if (parms.newValue != '') {
- var rows = JSON.parse(parms.newValue);
- var price = 0;
- var formated;
- rows.forEach(function(item) {
- var value = item.value
- .replace(/\./g, "")
- .replace(",", ".");
- price += parseFloat(value);
- });
- formated = price.toLocaleString("en-US", {
- style: "currency",
- currency: "USD"
- });
- g_form.setValue("v_total", formated);
- } else {
- g_form.setValue('v_total', '$0');
- }
- }
- };
- // Remove listener in client script of type submit
- scope._refundDereg = scope.$on('field.change', refundListener);
- }
- // CATALOG SCRIPT SUBMIT
- function onSubmit() {
- var scope = (this && this.angular ? this.angular : angular).element((this && this.document ? this.document : document).body).scope();
- if (scope && scope._refundDereg) {
- try {
- scope._refundDereg(); // remove listener
- } catch (e) {
- console.warn('Error cancelling the refund listener registration.', e);
- }
- delete scope._refundDereg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment