Jump to content

Hide the Edit button within Tabular Result page


Recommended Posts

Hello Alison, 

I will add the application to let you play with it.

You can implement this functionality using JavaScript.
First of all, you need to copy a value of a needed field in the HTML block adjust it as the <p> HTML element with class and hide it.
To copy the value use the parameters feature.

Then you need to insert the following code in the footer:

 

<script type="text/javascript">
document.addEventListener('DataPageReady', function () {
 var vals = document.getElementsByClassName("your_class_name");
  var buttons = document.getElementsByClassName("cbResultSetActionCell");
                
  for (var i=0; i < vals.length; i++){
    if (vals[i].innerHTML == your_value){
      buttons[i].style.display = "none";
    }
  }
});
</script>


You need to copy the class value of your <p> element in the "your_class_name" part and adjust the value of "your_value" part according to your conditions.
 

CaspioData_2018-Dec-05_1425 (1).zip

Link to comment
Share on other sites

@MayMusic

If you want to hide just Edit button and leave the details button,  use this code:
 

<script type="text/javascript">
document.addEventListener('DataPageReady', function () {
  var values = document.getElementsByClassName("your_class_name");
  var editButtons = document.getElementsByClassName("cbResultSetActionsLinks");

  var firstButton = 2;
  var secondButton = 3;

 for (i = 0; i < values.length; i++) {
    if(values[i].innerHTML == your_condition) {
      editButtons[firstButton].style.display = "none";
      editButtons[secondButton].style.display = "none"; 
    }
    firstButton += 4;
    secondButton += 4;   
  }
});
</script>

 

It is also adjustable if you have delete button:

 

<script type="text/javascript">
document.addEventListener('DataPageReady', function () {
  var values = document.getElementsByClassName("your_class_name");
  var editButtons = document.getElementsByClassName("cbResultSetActionsLinks");

  var firstButton = 2;
  var secondButton = 3;

 for (i = 0; i < values.length; i++) {
    if(values[i].innerHTML == your_condition) {
      editButtons[firstButton].style.display = "none";
      editButtons[secondButton].style.display = "none"; 
    }
    firstButton += 6;
    secondButton += 6;   
  }
});
</script>



 

Link to comment
Share on other sites

  • 4 weeks later...

Hey Carlson,

 

Your question is a bit off-topic to this thread, but the answer to your question is yes, you may.

 

If you wanted to "hide" the Delete button in general (NOT record-specific), you may paste>modify this code on your Footer with HTML Editor disabled in the Advanced tab:

<script>
  
  var condition = ("[@authfield:role]" != "admin"); //Your condition
  
  /*Edits are not necessary from this point onward */
  var deleteButtons = document.querySelectorAll('[data-cb-name="InlineDelete"]');
  
  if(condition) {
  	deleteButtons.forEach(function (elem) {
      elem.style.display = "none";
    });
  }
  
</script>

 

====

A per-record implementation is a bit more complex, paste the following code snippets in their respective places  with HTML Editor disabled. The only modification needed is the "condition"

Header

<script>
var toHide = [];

function hideDelete(idx, cond) {
if (cond) toHide.push((idx-1)*2);
}
</script>

 

HTML Block

<script>

var condition = ("[@field:created_by]" == "[@authfield:userid]");

hideDelete([@cbRecordIndex], condition);

</script>

 

Footer

<script>
var deleteButtons = document.querySelectorAll('[data-cb-name="InlineDelete"]');
toHide.forEach(function(elem) {
  deleteButtons[elem].style.display = "none";
  deleteButtons[elem+1].style.display = "none";
})
</script>

 

I hope this helps.

If you have questions, I'd suggest to start another forum thread then mention me in there to keep this thread clean.

 

Happy new year!

 

Cheers,

DN31337

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

×
×
  • Create New...