Jump to content

Display Link if Any Record Added


Recommended Posts

I have a tabular report and the link to the next page in the Footer.

By default, the report is empty, and I want users to add one or several records. However, I do not want users to proceed without adding at least one record.

I know that I should add JS if...else statement to the DataPage, however I have no idea on how to get the number of records there.

I have attached my app if necessary.

1398395605_Screenshotfrom2022-01-0516-22-09.png.e763db2b0800283465f8eaaa836376c9.png

I would appreciate any assistance

Tabular.zip

Link to comment
Share on other sites

Hi @deemuss

You can use one of the following codes in the Footer of the DataPage:

1. With this one, link will still be on the screen, but it would not redirect anywhere:

<a  id='aLink' href="[@app:URL_1]">Caspio</a>

<script>
document.addEventListener('DataPageReady', function (event) {
      const link = document.querySelector('#aLink');
      const message = document.querySelectorAll('.cbResultSetRecordMessage')[0];
      if(message.textContent === 'No records found.') link.href = 'javascript:void(0)';
});
</script>

 

2. This one will remove link from the page:

<a  id='aLink' href="[@app:URL_1]">Caspio</a>

<script>
document.addEventListener('DataPageReady', function (event) {
      const link = document.querySelector('#aLink');
      const message = document.querySelectorAll('.cbResultSetRecordMessage')[0];
      if(link){
           if(message.textContent === 'No records found.') link.remove();
      }
});
</script>

 

Link to comment
Share on other sites

Hello.

 

Here is one more way to do the same:

<a  id='aLink' href="[@app:URL_1]">Caspio</a>

<script>
document.addEventListener('DataPageReady', function (event) {
    if (document.querySelector('.cbResultSetDataRow[data-cb-name="data"]') == null) {
    document.querySelector('#aLink').style.display = 'none'
  }
});
</script>

 

Link to comment
Share on other sites

@Alexray 'if' statement is better in your example, because the user could set a custom message when there is no records.

But I would be careful using 'style.display', because the element is still the same and can be found using the console, and then easily 'hacked' into showing or clicking.

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