1 Reply Latest reply on Apr 24, 2014 7:59 AM by Magus069

    Have a field acting like Excel Cell

    Magus069 Level 4

      One of my clients have this request to have a field that can calculate operations for you but in only one field...


      I am wondering if there's a method already made for this...


      For exemple, in a field of hours, instead of inserting the number of hours directly we could insert the number of days he work with the number of hours and weeks... so the client could just insert 4 * 5 * 42 which will display the response in that same field... I can't make other fields for that cuz it's in a huge table and there is no space for more fields...


      Anyone have an idea on how to achieve something like so?


      Insert in a text field / decimal field / numeric field 4 * 5 * 42


      will return the result 840 in the same field on exit event..


      Thanks, Rob

        • 1. Re: Have a field acting like Excel Cell
          Magus069 Level 4

          Hi Rob,


          I found the solution so if anyone else is looking for something similar,

          you can set everything in the validate event of a text field preferably..



          if (this.rawValue != null){

                    // Validate the equation

                    var regExpression = new RegExp("\\d+(\\.\\d+)*|[\\(\\)\\+\\-\\*\\/]"); // Create a new Regular Expression Object.

                    // Set the regular expression to look for any equation's operators and numbers


                    var result = regExpression.test(this.rawValue); // Test the string


                    // If it fits regexp

                    if (result == true) {

                              // all is good and execute the equation

                              this.rawValue = Math.eval(this.rawValue);




                              // fail the validation.

                              xfa.host.messageBox("Please insert a valid equation to calculate.", "Information", 2);

                              this.rawValue = "";