Guest User

Example Code - Event Listener MRVS - deletar linha no MRVS

a guest
Nov 14th, 2025
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.84 KB | Source Code | 0 0
  1. /*
  2.  
  3. 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.
  4.  
  5. */
  6.  
  7. //CATALOG SCRIPT ONLOAD
  8.  
  9. function onLoad() {
  10.     var scope = (this && this.angular ? this.angular : angular).element((this && this.document ? this.document : document).body).scope();
  11.  
  12.     // avoids registering twice
  13.     if (scope._refundDereg) {
  14.         return;
  15.     }
  16.  
  17.     var refundListener = function(evt, parms) {
  18.         if (parms.field.name == 'vs_refund') {
  19.             if (parms.newValue != '') {
  20.                 var rows = JSON.parse(parms.newValue);
  21.                 var price = 0;
  22.                 var formated;
  23.                 rows.forEach(function(item) {
  24.  
  25.                     var value = item.value
  26.                         .replace(/\./g, "")
  27.                         .replace(",", ".");
  28.  
  29.                     price += parseFloat(value);
  30.  
  31.                 });
  32.  
  33.                 formated = price.toLocaleString("en-US", {
  34.                     style: "currency",
  35.                     currency: "USD"
  36.                 });
  37.  
  38.                 g_form.setValue("v_total", formated);
  39.             } else {
  40.                 g_form.setValue('v_total', '$0');
  41.             }
  42.         }
  43.     };
  44.     // Remove listener in client script of type submit
  45.     scope._refundDereg = scope.$on('field.change', refundListener);
  46. }
  47.  
  48.  
  49.  
  50. // CATALOG SCRIPT SUBMIT
  51.  
  52. function onSubmit() {
  53.  
  54.     var scope = (this && this.angular ? this.angular : angular).element((this && this.document ? this.document : document).body).scope();
  55.  
  56.     if (scope && scope._refundDereg) {
  57.         try {
  58.             scope._refundDereg(); // remove listener
  59.         } catch (e) {
  60.             console.warn('Error cancelling the refund listener registration.', e);
  61.         }
  62.         delete scope._refundDereg;
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment