6 Replies Latest reply on Nov 1, 2016 2:19 PM by Pavel_p

    Apex.checkbox values

    blue1234

      Hello all,

       

      I need some help in my issue:

       

      I am working in apex 4.2 and trying to call JavaScript function from checkbox field in IR.

       

      what I need to do is on click on checkbox , I need to call JavaScript function one if the value of the checkbox is check, and the other one if the checkbox is unchecked.

       

      because I have some calculation according the checkbox so if the user make check on checkbox I need to call JavaScript to make the calculation but if the user change the value of the same record to be unchecked then I need to make the calculation again.

       

      Note: I am using the checkbox to pass the rowid that will be used later at the submit to make the update.

       

      here is my query for the checkbox in IR.

      apex_item.checkbox(1,a.rowid,'UNCHECKED') flag, and then on column link , link Attributes : onclick="calc(#TRANS_AMOUNT#)".

        • 1. Re: Apex.checkbox values
          blue1234

          Any ideas!!

           

          I just want to know how to get the checkbox value in JavaScript, how to know the checkbox value is checked or unchecked?

           

          Thanks

          • 2. Re: Apex.checkbox values
            Scott Wesley

            Instead of using onclick, try create a dynamic action

            Event: Click

            Selection  Type: jQuery selector

            jQuery selector: :checkbox

            Condition: is not null

             

            You can now have true and false actions, based on if it's checked.

             

            In JavaScript actions, you can get the value of the checkbox using

            $(this.triggeringElement).val()

            You can use that same object to traverse the row around the checkbox, if you want to get/set values.

            You could also use link attributes to embed data to make it more accessible from the JS using data- attributes.

            • 3. Re: Apex.checkbox values
              Pavel_p

              Hi,

              I consider any JS calculations unsafe (mainly because of the lack of strongly typed variables, but it's just my opinion). If it's a problem to simply round a number in JS (Round to at most 2 decimal places in JavaScript - Stack Overflow ) with many different approaches and downsides, I have no idea how it can be used for any serious calculations. Also different languages have different ideas about decimal point characters and thousand separators, so if you plan a multi-language app, you should keep that in mind. Moreover, you'll probably have to take care of your report pagination because when you change your IR's page, selected rows will be lost.

              With all that said, I suggest to move your calculation server-side. For persisting selected values you can use for example this method Re: Interactive Report Check box looses check on record page navigation and once you're on the server and you also know what records are (de)selected, you can also simply perform your calculation there. Let's say you have an item PX_CALCULATION_RESULT, so just assign it a value in your PL/SQL DA and specify it as an Item to Return.

              Regards,

              Pavel

              • 4. Re: Apex.checkbox values
                blue1234

                thanks swesley_perth for your comment.

                I  have a question,

                how can I pass the value of my checkbox to jQuery selector: :checkbox, my checkbox exists in IR and I used this query to define it on the report(apex_item.checkbox(1,a.rowid,'UNCHECKED') flag).

                 

                I think if I can get the value of my checkbox which is the rowid then I can make my calculation in the DA

                because right now when I am calling the JavaScript function I am passing the amount to be used later in my calculation, the amount is a column in the same IR where the checkbox exist.

                 

                I tried before to get the value of my checkbox using APEX_APPLICATION.G_F01.COUNT in dynamic action but it didn't work .

                • 5. Re: Apex.checkbox values
                  blue1234

                  you are right, its so difficult to work with JavaScript with amount and has decimal places , but I couldn't find a way to do my calculation because I need to get the amount for the record that is checked by the user.

                   

                  and using the dynamic action I couldn't find away to do this, it will be so easier if i can get the value of my checkbox using dynamic action !

                  • 6. Re: Apex.checkbox values
                    Pavel_p

                    But you can quite easily get it's value. Please, read the documentation to apex_item.checkbox2 APEX_ITEM function (there is a p_value parameter), follow the example on the link above (Interactive report...) and eventually ask questions.

                    Also you cannot go wrong with creating an example here https://apex.oracle.com/pls/apex/f?p=4550:1:111542093469146::::: , share developer credentials to your workspace and your problem will be very likely solved in a short time.