We help IT Professionals succeed at work.
Get Started

Kintone JSedit

tyler Moore
tyler Moore asked
on
38 Views
Last Modified: 2020-01-30
I am using Kintone  JSedit (Java Script)? I am working on a basic application but my native language is not Java so I'm really at a disadvantage here and resources are thin.

I need to calculate a total using data entered in my form.  

Tyler
Comment
Watch Question
tyler MooreIT services

Author

Commented:
So basically to add more context, in Kintone I can embed JavaScript into it to complete functions. So what I've done is create this GUI, where you can input numbers into the Unit Price and Amount(qty). My desire is that through my JS it will automatically calculate the Total and display it in the box below. This is a over simplified example of what I intend to use it for but still learning JS as that's not my normal go to language.

2020-01-30-11_04_00-Test_APP---10---.png
Here is my code:
(function() {
    "use strict";
    var NUMBER = 'mynumber'; //field code of number field
    var ZEROFILL = 'zerofilled_number'; //field code of text field to set result into
    var NUMOFDIGITS = 8 //number of digits for the zero-filled number

    function zeroFill(value, length) {
        if (value.length >= length) { return value; }
        return (new Array(length).join('0') + value).slice(-length);
    }
 
    var events = ["app.record.create.change." + NUMBER, 'app.record.edit.change.' + NUMBER];
 
    kintone.events.on(events, function(event) {
        var record = event.record;
        var changes = event.changes.field;
        var length = NUMOFDIGITS;
        record[ZEROFILL].value = zeroFill(changes.value, length);
        return event;
    });
    // Events triggered while the record is in edit mode
    kintone.events.on(['app.record.edit.show', 'app.record.create.show', 'app.record.index.edit.show'], function (event) {
        // Restricting the input of the "Total" field
        event.record['Total'].disabled = true;

        return event;
    });
})();

Open in new window

CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Top Expert 2013

Commented:

Did the above answer your question?  


While it is true a calculation is typically not to be relied on it is needed for the user.


For a ecommerce site / shopping cart you do in fact calculate totals for the user with javascript as that will give a quick visual answer without refreshing the page. In theory you could use an ajax request but more than likely that is not needed.


However, on the back end when you are going to send a payment amount to the processor, you only send the item and quantity. Then your back end code looks up the price and does any calculation including any final shipping if that is needed. 


In short, do you still need help with the JS calculation?  

tyler MooreIT services

Author

Commented:
I figured it out on my own. I'm not familiar as I want to be with the whole thing but ultimately it'll work out.
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE