Grand total with javascript

elle

Member
Hi everybody,

since weeks I try to have a grand total in a group under a repeated group. I tested every code, posted here in the forum, but nothing happens.
Even a simple
Code:
alert(this.id);
gives me an "undefined"! I cannot get informations via javascript. I use Mozilla Firefox and Firebug and for testing also Safari. Both with the newest Updates.

What is wrong? Can you please look at my site? (access in my site informations)
I'm very frustrated, because I have to present this project at the end of this month...

Please please help me urgend.

Best regards
Elle
 
To explain my posting from yesterday:

The elements, I've tryed to enter the js code are on the form "GPA-Abrechnung" and in the javascript-tab of the elements:
2_ums (Umsatz - field - validation: notempty):
Code:
alert(this.id);
(this gives me an "undefined"!)

and the element 2_anz (Anzahl - field - validation: notempty):
Code:
total();
who's stored in the file "form_14.js" with this code:
Code:
requirejs(['fab/fabrik'], function () {
function total() {
alert("springt an!");
  // replace 1 with the form's id
  var formRef = 'form_14';
 
  // Replace with the element name
  var elementName = '0_gpa_abrechnung___1_provi_gesamt';
 
  // The element containing the line items total
  var totalElement = '0_gpa_abrechnung_19_repeat___2_provi';
  var v;
  var total = 0;
 
  // Get the form's elements
  var elements = Fabrik.blocks[formRef].formElements;
 
  // Loop over the elements and if their key contains the elementName update the total
  elements.each(function (element, key) {
 
      if (key.contains(elementName)) {
      v = element.get('value').toFloat();
      if (typeOf(v) !== 'null') {
      total += v;
      }
      }
  });
 
 
 
  // update the total element
  elements.get(totalElement).update(total);
}
 
// Add events when adding/deleting groups
Fabrik.addEvent('fabrik.form.group.duplicate.end', function (form, event) {
  total();
});
 
Fabrik.addEvent('fabrik.form.group.delete.end', function (form, event) {
  total();
});
 
document.addEvent('blur:relay(input[name^=0_gpa_abrechnung_19_repeat___2_provi])', function () {
total();
})
})
 
function vkDatum() {
    var start= form_14.formElements.get('0_gpa_abrechnung___1_von').getValue();
    var end = form_14.formElements.get('0_gpa_abrechnung___1_bis').getValue();
    var diff = start.compare(end);
    var result = diff > 0 ? true : false;
}
/*
form_14
0_gpa_abrechnung___1_provi_gesamt
0_gpa_abrechnung_19_repeat___2_provi
*/
This gives me the error:
"ReferenceError: total is not defined
total();" on element-min.js line 1 > eval

Please would you have a look?

Nice regards
Elle
 
How do I get to the form? I've tried every link / page I can find on the front end, and the login you provided us doesn't seem to have backend access:

Warnung
Kein Zugang zum Administrationsbereich dieser Website!

-- hugh
 
Hi Hugh,

oups - sorry. I've changed the access level long time ago. Now you'll have access to the frontend login and also the backend.

The concerned form, for where I'm looking for help is "GPA-Abrechnung" (in frontend you can see only, if you are logged in!) and the group is "2_verkauf". The fields, I have tested js are (just for testing) "2_anz" and "2_ums". You can certainly change the js there to make it working.

From today I am in Munich to play with my band an further in Switzerland. So I can't reply that fast, but I'll try.
Thanks for helping me.

--Elle--
 
Can you ...

a) make the user a super admin (I don't seem to have much access to anything on the backend).

b) fill out your ftp details in My Sites, so I can edit the custom form JS file.

What instrument and style of music do you play?

-- hugh
 
Hi Hugh,

thanx for your support!
All is done and preparated for you.

I'm playing in a party-rock-band named "BIBA & die Butzem?nner". We play mostly rock and pop and some oldies. A couple times we played on the "German Fest" in Milwaukee / WI. Maybe next year we will be there again. I play the keyboards and sometimes a bit of guitar and drums...

Hope to read from you. Now I'm on the way to Munich...

Kind regards
--Elle--
 
Ah, a fellow keyboard player. I play the Hammond B3, the "real thing", all 400 pounds of it, plus Leslie.

I'll take a look at the script again now.

-- hugh
 
OK, the total() script is now working, on add/remove group.

Not much point having that blur trigger in the script though, as that's on the line item's calc, which you typically wouldn't focus in to, or blur out of.

So what you need to do now is making sure total() gets fired when you change any of the elements on the line items that cause a re-calc of the line item total, which you can do via the element's JS events.

Let me know if you need more help with that.

-- hugh
 
Hi Hugh,

I'm back from Switzerland.

Thank you very much for your support. Unfortunally the grand total is'nt working. :(

I've changed the javascript in both elements ("2_anz" and "2_ ums") on a blur event to fire the funktion total().
Also changed the element "1_provi_gesamt" in the group Rechnungsdaten from a calc element to a field element.

As you can see in the screenshot of Firebug, nothing is defined! What does that mean?
Can you have a look once again?

Keep on rocking ;-)
--Elle--
errors Firebug.png
 
I noticed the Modernizer error when i first logged on, that's nothing to do with us.

I'll take a look at the blur stuff.

-- hugh
 
OK, you should be able to remove all the 'blur' events, or whatever you are using on the element JS, which call total(). The form_14.js now just listens for a fabrik.calc.update event, and runs total() on that. So the script should be self contained, no need to trigger it from anywhere else.

-- hugh
 
Hi Hugh,

many thanx for your support! :)

I tried the code and it was working.
But now, I've made some editings in other elements and - what should I say - the code does'nt work...
It only works, if I put another line in my repeated group. So I think, the 'fabrik.form.group.duplicate.end' and the 'fabrik.form.group.delete.end' events are firering up the total() function.
I think, it's a problem with the 'fabrik.calc.update' event.

I was searching for some help for the 'fabrik.calc.update' event, but could'nt find anything.
Maybe you can explain it to me, how to handle the 'fabrik.calc.update' event.

Can you please have a look again on my form_14.js?

Hope to hear from you.

All the best
--Elle--
 
Well, you seem to have changed that 'provi' element from being a calc, to a field. The way the script I gave you worked was, that 'provi' element you want to do the sum on was a calc. So the script listened for the fabrik.calc.update event, which gets fired by calc elements when the get updated, checked to see if the calc firing it was 'provi', and if so, run total:

Code:
Fabrik.addEvent('fabrik.calc.update', function (el, val) {
if (el.element.id.test(/0_gpa_abrechnung_19_repeat___2_provi/)) {
//***********************************************************************
//alert('springt an!');
//***********************************************************************
total();
}
});

But now that element is no longer a calc, that code above won't do anything.

I'd suggest just calling total() from the end of your new provision() function.

-- hugh
 
Hi Hugh,

thats what I thought. I putted the callng total() into my new provision() function and now it works!
Thank you again for you advices.

Best regards
--Elle--
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top