8 Replies Latest reply on Jun 12, 2017 6:29 PM by John Snyders-Oracle

    APEX 5.1.1 IG - how to set value of a hidden column

    Marko Goricki

      Hi,

       

      can anybody give me a clue how to set value of a hidden column in Interactive Grid.

       

      I have a sample here.

       

      There's a button "Set salary to 1000 of selected emp" on this page that executes the following JS code:

      var g = apex.region('rgnEmp').widget().interactiveGrid('getViews','grid');
      var r = g.getSelectedRecords()[0];
      g.model.setValue(r, 'SAL', 1000);
      

       

      https://apex.oracle.com/pls/apex/f?p=103570:4:Column SAL is defined as hidden and not protected.

       

      The error that I see in console is:

      Uncaught Error: Set value not allowed for field.
      

       

       

      Tested on apex.oracle.com (version5.1.1.00.08).

       

      Thanks in advance!

       

      Br,

      Marko

        • 1. Re: APEX 5.1.1 IG - how to set value of a hidden column
          John Snyders-Oracle

          Hi Marko,

           

          Very interesting question. Looking into why it is not working we can learn a lot.

           

          IG takes care to not allow the client to change data that it shouldn't. It does this with various checksums. It also does some checking in the model API. So the error you are getting is because the model setValue method first checks that the record can be edited (it can) and then if the field can be edited (is not readonly). A column/field is readonly if the column/field metadata has the readonly property = true or if the record column/field metadata has a ck (checksum) property.

           

          You can see the field metadata from the console like this:

          apex.region("emp").widget().interactiveGrid("getCurrentView").model.getFieldMetadata("SAL");

          You will see that when SAL is type Hidden that readonly is true

           

          You can see the record metadata for the selected row from the console like this:

          rec = apex.region("emp").widget().interactiveGrid("getSelectedRecords")[0];

          rec[rec.length-1].fields.SAL

          You will see that there is a ck property.

           

          So if you set readonly to false and delete the ck property then you will find that setValue no longer complains. However if you save the IG you get a server side error.

           

          What you are trying to do, set the value of a hidden column, is reasonable even if not very common. However as you have found even when Value Protected is No the record metadata contains the ck property and the field metadata is readonly. This doesn't seem right and I have entered bug 25891453 to track the issue. Until that is fixed you will not be able to set a hidden value.

           

          So what you can do is use a Text or Number Field column. Give it a heading label etc. just as if you wanted to see the column. Then run the page and hide the column. To keep the user from being able to show the column again add this column advanced JavaScript code to the SAL column:

           

          function(config) {

              config.features.canHide = false;

              return config;

          }

           

          Interesting thing about the canHide attribute. It doesn't mean that the column must be visible just that the user has no ability to hide or show it. So the column still shows up in the list of columns in the Columns dialog but you can't check or uncheck it. Perhaps we should think about if it should even be shown in this case. Seems confusing. Depending on your use case you may want to disable the Columns dialog by customizing the action or toolbar menu.

           

          One minor thing is that your setValue call should pass in the value as a string like so:

          g.model.setValue(r, 'SAL', '1000');

          The model doesn't care but the server and any column that uses with a column item for input will be dealing with strings.

           

          After doing all this I see that there is another strange issue that I still need to track down. It is likely a bug. When you click the button to update the salary the model notifies the view but the view is now confused about what got updated and updates a different column.

           

          I'll keep investigating.

           

          Regards,

          -John

          1 person found this helpful
          • 2. Re: APEX 5.1.1 IG - how to set value of a hidden column
            Sina

            I have the same problem. I need to set the LAST_UPDATED  and USER_ID in an IG however it through uncaught error. i also have the same problem with display only field.

            in my grid i have the tax column which i would like to calculate with java script but i receive uncaught error.

            is there any update on this issue

            • 3. Re: APEX 5.1.1 IG - how to set value of a hidden column
              Marko Goricki

              Thx for effort and great explanation!

              I was also going in this direction (with hidden text field columns) and in some cases I found strange behavior with wrong updates (as you mentioned). I found a workaround for my case, but I still think it should be possible to set value of a hidden column at least the ones that are not protected.

               

              Thanks again!

               

              Br,

              Marko

              • 4. Re: APEX 5.1.1 IG - how to set value of a hidden column

                Hey,

                have you hide the Column in JS or in CSS?

                Try to hide it in CSS and try again if it works

                 

                Regards

                Pierre

                • 5. Re: APEX 5.1.1 IG - how to set value of a hidden column
                  Nikhil Reddy A

                  Hi John,

                   

                  I follwed your steps to update an hidden cell, but unfortunately as you mentioned the setValue function is confused and it is settiign the value of an different cell, instead of the one that I pass in the setValue function.

                  Couly you please help me know if there is any workarround?

                   

                  Also I face an issue when I define more than one column in an IG as a POP-UP lov item. In that case only one gets Pop-up lov gets rendered properly and the other popup gives an apex internal error saying 'Unable to find item ID for CXXXXxxX in Application'. I believe it is a bug.

                   

                  Best Regards

                  -Nikhil

                  • 6. Re: APEX 5.1.1 IG - how to set value of a hidden column
                    Denes Kubicek

                    Marko,

                     

                    Thanks. This is what happens when I try to save the grid:

                     

                     

                    Obviously it works until the process is involved and even though the colum has no source the problem shows up.

                     

                    Denes Kubicek

                    • 7. Re: APEX 5.1.1 IG - how to set value of a hidden column
                      Denes Kubicek

                      At the end I managed to make it working by using a text item and setting the custom attributes to readonly="true". That is not nice but it works.

                       

                      Denes Kubicek

                      • 8. Re: APEX 5.1.1 IG - how to set value of a hidden column
                        John Snyders-Oracle

                        John Snyders-Oracle wrote:

                         

                        After doing all this I see that there is another strange issue that I still need to track down. It is likely a bug. When you click the button to update the salary the model notifies the view but the view is now confused about what got updated and updates a different column.

                         

                        I'll keep investigating.

                         

                        While working on something else I stumbled on this problem again and found the reason. No reasonable workaround. I entered bug 26260818.

                        Regards,

                        -John