5 Replies Latest reply on May 13, 2010 3:53 AM by BhaskerChari

    calculator : bindings of multiple textinputs

    svi_beijing

      hi!

       

      I am working on a kind of form with textinput created dynamically:

       

      unit price = comes from database

      quantity = user can change

      price = should be calculated

      discount = user can change

      total = should be calculated

       

      at the moment I have something like this:

       

      price.text = fct_get_price(unit_price.text, quantity.text)

       

      it works, as long as I don't bind the data like:

       

      fct_init_binding(tf_price, tf_qty);

       

      private function fct_init_binding(textInputDst, textInputSrc):void {

      BindingUtils.bindProperty(textInputDst, "text", textInputSrc, "text");

      }

       

      how can this be solved?

       

      thanks a lot for any hints!!!

        • 1. Re: calculator : bindings of multiple textinputs
          BhaskerChari Level 4

          Hi svi_beijing,

           

          I din't get your question correctly. Can you please elaborate....?

           

           

          Thanks,

          Bhasker Chari.S

          • 2. Re: calculator : bindings of multiple textinputs
            svi_beijing Level 1

            thks for your reply!

             

            Bildschirmfoto 2010-05-13 um 15.11.43.png

             

            in case user change the qty the price field should calculate = unit price * quantity

            in case user change days and discount the total should be calculated like = ((unit price * quantity) * days ) - discount

             

            problem is the bindings seems not to work

             

            thanks!

            • 3. Re: calculator : bindings of multiple textinputs
              David_F57 Level 5

              hi,

               

              If you create a 'total' var with getters and setters you can then bind to the total var. The calculation you need can be done in the setter which would take the numeric values and return a string.

               

              David

              • 4. Re: calculator : bindings of multiple textinputs
                svi_beijing Level 1

                hi and thks very much for your answer,

                 

                but to be honest: I really have no idea how to do it.

                 

                in case you can explain me how to do this for:

                 

                unit_price * quantity = price

                 

                would be enough to get me to the final result.

                 

                this works:

                 

                     var tf_qty:TextInput = new TextInput();

                    tf_qty.text = "1";

                    tf_qty.width = 30;

                    tf_qty.id=count_form+"_qty";

                 

                    var tf_price:TextInput = new TextInput();

                    tf_price.text = fct_get_price4qty(tf_qty.text,tf_unit_price.text).toString();

                    tf_price.width = 50;

                    tf_price.id=count_form+"_price";

                 

                     private function fct_get_price4qty(tf_qty, tf_unit_price):Number {

                          return int(tf_qty)*int(tf_unit_price);

                     }

                 

                but as soon as I add a binding like this it's not working:

                 

                 

                   var tf_qty:TextInput = new TextInput();

                    tf_qty.text = "1";

                    tf_qty.width = 30;

                    tf_qty.id=count_form+"_qty";

                 

                    var tf_price:TextInput = new TextInput();

                    tf_price.text = fct_get_price4qty(tf_qty.text,tf_unit_price.text).toString();

                    tf_price.width = 50;

                    tf_price.id=count_form+"_price";

                 

                 

                     fct_init_binding(tf_price, tf_qty);

                 

                     private function fct_get_price4qty(tf_qty, tf_unit_price):Number {

                          return int(tf_qty)*int(tf_unit_price);

                     }

                 

                     private function fct_init_binding(textInputDst, textInputSrc):void {

                          BindingUtils.bindProperty(textInputDst, "text", textInputSrc, "text");

                     }

                 

                 

                the binding again is working if I remove my transform function:

                 

                 

                var tf_qty:TextInput = new TextInput();

                    tf_qty.text = "1";

                    tf_qty.width = 30;

                    tf_qty.id=count_form+"_qty";

                 

                    var tf_price:TextInput = new TextInput();

                    tf_price.text = tf_qty.text;

                    tf_price.width = 50;

                    tf_price.id=count_form+"_price";

                 

                 

                     fct_init_binding(tf_price, tf_qty);

                 

                     private function fct_init_binding(textInputDst, textInputSrc):void {

                          BindingUtils.bindProperty(textInputDst, "text", textInputSrc, "text");

                     }

                 

                 

                but I really have no idea how to get it working, sorry ...

                • 5. Re: calculator : bindings of multiple textinputs
                  BhaskerChari Level 4

                  Hi ,

                   

                  Sorry reaching you late...I was out on a work

                   

                  The code in which you have sent ...whether this code gets executed each time the user changes the quantity or price...?

                   

                  Are you using the DataGrid component..? It seems so...

                   

                   

                  If you are using the datagrid then how you are accessing the individual row textinputs...?

                   

                  If you can email me or post me a working version of your sample code which depicts your problem then I may help you..?

                   

                  Thanks,

                  Bhasker Chari.S