Jump to content

Java Script is not working correctly HELP!


Recommended Posts

Details of the issue:

A DataPage is using a custom script with a button that creates a record. The button is always passing the same ID as parameter to the results page, but it should pass the ID assigned to a chosen record. The record created by the button has a correct ID.


Expected Result: Correct ID is passed to the next page.


Actual Result: ID is passed incorrectly on the results page, but correctly on the created records.

 

Here is the Java Script that is not working.  Can anyone look at this and determine why  when the selection is made, that the correct Template ID is not passing?  The passed ID is always the same, however the record that is created in the table is actually correct.

 

This is in the HEADER

<style>
thead th:nth-child(7) {
display: none!important;
}
.cbResultSetCalculatedField {
display: none !important;
}
.hidden {
display: none !important;
}
</style>

<style>

.cbResultSetTableHeader > th:nth-child(8), .cbResultSetDataRow td:nth-child(8), .cbResultSetTableHeader > th:nth-child(9), .cbResultSetDataRow td:nth-child(9) {
display: none;
}

</style>

 

This is a Calculated Field

CASE
WHEN [@field:SelectTemplate] = 'True'
THEN
''
ELSE
'hidden'
END

 

This is an HTML Block

<a class="[@calcfield:1]" href="https://www.bluefr8.com/post-template.html/?TN=[@field:TemplateNo]">POST TEMPLATE</a>

 

This is in the Footer

<!--
1. SelectTemplate checkbox is checked\unchecked automatically when editing record
2. Update button is renamed to "POST TEMPLATE"
3. When "POST TEMPLATE" button is clicked, user must be redirected to the following URL: https://www.bluefr8.com/post-template.html/?TN=[@field:TemplateNo]

-->

<script>
if (typeof addObserver == 'undefined') {
const addObserver = () => {
new MutationObserver((mutations)=>{

if (mutations[mutations.length-1].addedNodes.length>0) {
 if (mutations[mutations.length-1].addedNodes[0].getAttribute('class') != null) {
 if (mutations[mutations.length-1].addedNodes[0].getAttribute('class').indexOf('cbResultSetCancelButton')>-1) {
console.log(mutations[mutations.length-1].addedNodes[0])
document.querySelector('[name*="InlineEditSelectTemplate"]').click()
let updBtn = document.querySelector('input.cbResultSetModifyButton')
updBtn.value = 'POST TEMPLATE'
console.log("https://www.bluefr8.com/post-template.html/?TN="+"[@field:TemplateNo]")
updBtn.addEventListener('click', ()=>{
window.location.href = "https://www.bluefr8.com/post-template.html/?TN="+"[@field:TemplateNo]"

})

}
}
}
}).observe(document.querySelector('body'), {childList: true, subtree: true})
}
addObserver ()
}
</script>

 

Link to comment
Share on other sites

Hi @Rob2268,

What's the DP type where this is being used? Having a sample screenshot or URL would be very useful. From looking at the code, you can try adding a foreach to update the values for each cell/row accordingly since you need to get the value of each row, or you can move the code from the Footer to the HTML block, which will run the code once per row.

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