Jump to content
  • 0

Hide and disable Delete and Submit button based on condition


KG360

Question

In a report details page, I need to allow only the record creator to make changes to and delete the record. Other users belonging to the same account can view the record. This is [partly] achieved through disabling fields in the report details page for users who have not created the record.

The issue is that any user can hit 'Delete' and erase the record. 

How do I hide and disable both the Delete and the Submit buttons? The condition is: Current user ID != the record user ID.

As always - appreciate any guidance on this!

KG

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hello @KG360,

As far as I understood, in the table, you have a field to store the ID of the user who submitted this record. 

1) If it is a stand-alone Details page, it is possible to remove the whole container with buttons. 

If the buttons are hidden and disabled, it is possible to enable them and make them visible through the browser`s console. 

So, it is more secure to remove the element from the page.

This script should be added to the Footer of the Details page. 

<script>
document.addEventListener('DataPageReady', hideButtonsHandler)
   
function hideButtonsHandler(){

    const curentUser = '[@authfield:ID]'; 
    const submittedBy = '[@field:submitted_by]';
    const btnsContainer = document.querySelector('.cbBackButtonContainer');

    if(curentUser !== submittedBy) {
         btnsContainer.remove();
     }
document.removeEventListener('DataPageReady', hideButtonsHandler)  
}
</script>

In this script, please replace the parameters. 

In my example, the field name from the table where the user's ID is stored is named 'submitted_by'. 

And the user ID from the Authentication is named 'ID'.

You may use an 'insert' button to add the field names:

8Snp4s5.png

2) If the Details page is a part of the Report (Tabular,  Gallery, List) DataPage, then the container with buttons includes the 'Back' button.

In this case, it is possible to remove the 'Update' and the 'Delete' buttons and not the whole container with the buttons. 

<script>
document.addEventListener('DataPageReady', hideButtonsHandler)
   
function hideButtonsHandler(){

    const curentUser = '[@authfield:ID]';
    const submittedBy = '[@field:submitted_by]';
    const updateButton = document.querySelector('.cbUpdateButton');
    const deleteButton = document.querySelector('.cbDeleteButton');

    if(curentUser !== submittedBy) {
         updateButton.remove();
         deleteButton.remove();
     }
document.removeEventListener('DataPageReady', hideButtonsHandler)  
}

</script>

Feel free to update the thread if you have questions. 

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
Answer this question...

×   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...