Jump to content
  • 0

Conditional Link in DataPage Header


Peterson

Question

We have a details DataPage that includes information common to multiple authenticated users. We want to include an [EDIT] button in the header but only for certain authorized users. We control that access with a checkbox and the checkbox field is included in the view used for the authentications. I basically want to have either a link or a message explaining why they can't edit it.

<script type="text/javascript">
document.addEventListener('DataPageReady', function(event){
if("[@authfield:Editor^]" == "Yes"){
    <a href="https://domain.com/edit_page?id=[@id]">EDIT</a>;
}
else{
    <span>Only authorized employees are allowed to edit their company information.</span>;
}
});
</script>

 

The EDIT link does not show up on my datapage where this Header is located. What am I missing?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello @Peterson,

Please try the following:

1) Add the span or div element with the ID to the DataPage Header.

For example:

<span id='edit_link'></span>

JWT5Rco.png

 

2) Add this code to the DataPage Footer 

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

const linkElement = document.getElementById('edit_link'); //save the element form the Header to the variable

if("[@authfield:Editor^]" === "Yes"){
   linkElement.innerHTML = '<a href="https://domain.com/edit_page?id=[@id]">EDIT</a>'; //change the innerHTML property for the element
}
else{
    linkElement.innerHTML = '<span>Only authorized employees are allowed to edit their company information.</span>';
}
});
</script>  

 

Feel free to update this thread if you have any further 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...