Visual Builder

Get Involved. Join the Conversation.

Topic

    Rob Raftery
    Refresh page that has validator errors
    Topic posted August 21, 2019 by Rob RafteryRed Ribbon: 250+ Points 
    13 Views, 6 Comments
    Title:
    Refresh page that has validator errors
    Content:

    See attached image...

    I have a page that has validation on an input text component.  I also have a "Reload" button that is supposed to allow the user to simply reset the page to it's original values from when entering the page.  The "Reload" buttons works fine if there are no validation errors.  However, in the attached example, the user is forced to enter any value in the input text to satisfy the validation error before they can press the "Reload" button to refresh the page.  Is there a way I can override the validation errors to refresh the page?  I have tried calling the same action chain that is executed on VBEnter, but nothing happens.

    Image:

    Comment

     

    • Shay Shmeltzer

      Try and see if calling a Reset Variable action on the variable that populate the table before doing the new fetch helps.

       

      • Rob Raftery

        Hi Shay,

        Thanks for the reply.  I had tried the Reset Variables, but I couldn't get it to work.  I'm using an ADP to load the editable table.  In the reset, I had tried both options:

        1. $page.variables.SVCDEF_Array - Resetting the entire object
        2. $page.variables.SVCDEF_Array.data - Resetting just the data portion

        Also, when reloading the main ADP, I am using a backup ADP array that I load at the same time I am loading the main ADP.  When I am reloading the main ADP, I have tried using both options:

        1. Assigning the entire backup ADP to the main ADP
        2. Assigning just the data portion of the backup ADP to the main ADP

        In all cases, the main ADP ends up empty.  I have attached the inspect -> console (console_resetting_ADP_and_using_ADP_backup_to_reset.txt) so you can see the exception.

        I have even tried calling my reload page action chain, which I call on vbEnter, to reload the page instead of assigning my backup ADP to my main ADP, but I get the same results.  In fact, it looks like it never gets to the point of calling my reload page action chain.

        The only way I could get this to work, was to write my own JS function which simply loops through all the input text components in my editable table and calls the reset property.

        for (i = 0; i < VariableArray.data.length; i++) {
              document.getElementById([[ComponentName + i]]).reset();
            }

        Is there a way to see the JS code behind the Reset Variables action that VBCS is doing when you calling that step?  I'm curious as to what it is doing.

        Also, if I may, I have a slightly unrelated question.  While doing all of this input text validation, I would like to be able to dynamically change the state of the input text in my editable array from readonly false to readonly true to prevent the user from being able to overwrite the contents.  Everything I have tried isn't working.  The main thing I have tried that I though should work is to call the function below to change each input text to readonly = true based on a certain condition.  However, when running the application, I am still able to update the text.

        for (i = 0; i < VariableArray.data.length; i++) {
              if (VariableArray.data[i].COSS_SERVICE_DEFINITION_NAME == VariableArray.data[i].L2CW_SERVICE_DEFINITION_NAME) {
                document.getElementById([[ComponentName + i]]).readOnly = true;
              }
            }

        Thanks for all your valuable help.

        Rob

        • Shay Shmeltzer

          One more thing to check, fire a data provider refresh event on the ADP after you do the new fetch:

           

          • Rob Raftery

            Thank you Shay!

            Using the Fire Data Provider Event worked.  I actually tired using it in two different circumstances and both worked:

            1. I did as you suggested and fired it immediately after fetching my data from my REST endpoint and prior to assigning the data from the REST endpoint to my ADP.
            2. Rather than fetching my data again, I was using a backup array that I loaded at the same time I loaded my ADP during vbEnter.  When the user clicked the Reload button, I was simply reassigning my backup array to my ADP.  I added the Fire Data Provider Event just before I reloaded my ADP and it workes as well.

            Thanks for your help.

        • David Konecny

          Few comments:

          * For data reset/update always use $page.variables.SVCDEF_Array.data - that is array with your rows and that needs to be reset or updated. I personally would just use assignVariable action and assign into $page.variables.SVCDEF_Array.data new data array AND set "reset=empty" (in the assign variable mapper UI). That should do it!

          * re "the user is forced to enter any value in the input text to satisfy the validation error before they can press the Reload" - but that is how you coded it, no? Out of the box button can be clicked and execute any chain it has associated. Are you disabling the button when the form is not valid?

          * the exception from the console could be the cause why your table update fails - it looks that one of table's column is trying to render COSS_SERVICE_DEFINITION_NAME property of an object which is undefined. Try to fix that first. Maybe row data assigned into $page.variables.SVCDEF_Array.data contains row which is undefined??

          * re "make edit box readonly" - you can easily do that directly in the HTML. eg <oj-input-text value="..." readonly=" {{ $current.row.someAttribute }}"></oj-input-text>

          -David

          • Rob Raftery

            Dave,

            Thank you for your comments.

            1. I have used "reset=empty" before.  However, I needed to do something different in this case because, as you mentioned in your second comment, I am doing page validation that forces the user to enter something in the input text.  Reloading the array and setting "reset=empty" was not working for me.
            2. I am doing validation to force the user to enter something in the input text, but imagine the page was pre-populated with values in each input text.  The user decides to change the value in one of the input texts'.  However, he forgot what the original value was and the input text is now empty.  I offer a Reload button to return the page back to the way it was upon vbEnter.  I was looking for a way to avoid the user having to enter any value in the input text just to get by the validation.  It saves them an extra step.
            3. I did make sure the ADP have values in every row.
            4. I am looking for a way to dynamically set readonly on any one or multiple input texts' in my editable table based on a condition.  As I am loading my ADP, I want to be able to set the readonly property of each input text to false if a certain condition is true.  I am thinking I need to do this using a javascript function, but the things I have tried are not working.