Jump to content

Hide/Show Update button when certain condition is met


Recommended Posts

I have an Update page where I want to disallow users from updating the form when the CurrentProcess != 00 or 05

I have the following script placed in the footer, it works when there is only one condition [("[@field:CurrentProcess]" != "00")] but does not work when I include [|| ("[@field:CurrentProcess]" != "05")]. 

Is there anything wrong with the script?

Thanks!

<script>
document.addEventListener('DataPageReady', function (event) {
  if (("[@field:CurrentProcess]" != "00") || ("[@field:CurrentProcess]" != "05")) {
    document.getElementsByName("Mod0EditRecord").forEach(function(elem) {
      elem.style.display= 'none';
    });
  }

});
</script>

 

Link to comment
Share on other sites

Hi @beryllium,

A standard way of achieving this without using JavaScript is below:

  • Add a Header/Footer to your page.
  • Enter following code to hide the existing Update button:

               <style>

              .cbUpdateButton {
                    display: none !important;
               }

             </style>

  • Add a new section and in it add an HTML Block.
  • Enter following code to add a custom Update button:

               <div id="update" align="center">
                         <input type="submit" class="cbSubmitButton" value="Update" />
               </div>

               image.thumb.png.c7af4866682dd8f06dce2bad89b811f8.png

 

  • Now add a Rule. It should look like below:

              image.thumb.png.24668f349199086f9b9dacdd432ae40a.png

 

                Replace "Value" with your field name.

                I hope this helps.

 

                 Regards,

 

 

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
On 6/17/2022 at 1:28 AM, BaySunshine said:

Hi @beryllium,

A standard way of achieving this without using JavaScript is below:

  • Add a Header/Footer to your page.
  • Enter following code to hide the existing Update button:

               <style>

              .cbUpdateButton {
                    display: none !important;
               }

             </style>

  • Add a new section and in it add an HTML Block.
  • Enter following code to add a custom Update button:

               <div id="update" align="center">
                         <input type="submit" class="cbSubmitButton" value="Update" />
               </div>

               image.thumb.png.c7af4866682dd8f06dce2bad89b811f8.png

 

  • Now add a Rule. It should look like below:

              image.thumb.png.24668f349199086f9b9dacdd432ae40a.png

 

                Replace "Value" with your field name.

                I hope this helps.

 

                 Regards,

 

 

Very nice solution. I tried it, and it works, but I could not do the same with the Delete button. I used a similar script, but it might be the wrong syntax. <div id="delete" align="center">
                         <input type="delete" class="cbDeleteButton" value="Delete" />
               </div>

I tried it in the same HTML block as the Update button and in a separate HTML block; neither worked for the Delete button. 

any further guidance is much appreciated! Also: How 'safe' is hiding the button, the Delete in particular. Is it sufficient to Hide or must one also disable?

 

KG

Link to comment
Share on other sites

2 hours ago, KG360 said:

Very nice solution. I tried it, and it works, but I could not do the same with the Delete button. I used a similar script, but it might be the wrong syntax. <div id="delete" align="center">
                         <input type="delete" class="cbDeleteButton" value="Delete" />
               </div>

I tried it in the same HTML block as the Update button and in a separate HTML block; neither worked for the Delete button. 

any further guidance is much appreciated! Also: How 'safe' is hiding the button, the Delete in particular. Is it sufficient to Hide or must one also disable?

 

KG

Hi @KG360,

Please check this forum post for a custom delete button. A custom delete button will not work without additional scripting. Also, you need to have the type attribute as type="button" instead of type="submit" in the button code from this post.

 

Regards,
SP

Link to comment
Share on other sites

These solution from @CoopperBackpack work perfekt! I liked that it was not necessary to involve any other elements than the authentication field and the record creator ID. When they are the same the user have editing rights, if not user can only view the content. I also disabled the fields that could otherwise be edited.  

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...