I have been using WeBlocks to try and create some JavaScript for a range slider but came up against an issue. I have the range slider working in the most part but I am having an issue with the decimal points to show money values. I have attached the links below. I have reached out to WeBlocks but not heard anything back for a while and need to get this project completed. Within the link below if you move the slider to 7 Candidates the numbers go really long and I need to limit it.
const price = document.querySelectorAll(".cost_per_head");
// const price = document.querySelectorAll("[data-price]");
price.forEach((item) => {
item.textContent = new Intl.NumberFormat("en-EN", { style: "currency", currency: "GBP" }).format(item.textContent);
// returns a string with the currency symbol and the price with decimal places => ÂŁ1,000.00 or ÂŁ100.00
// item.textContent = new Intl.NumberFormat("en-EN", { style: "currency", currency: "GBP", maximumFractionDigits: 0 }).format(item.textContent);
// returns a string with the currency symbol and the price without decimal places => ÂŁ1,000 or ÂŁ100
});
If you do want to use additional JS, you can just make a script that will truncate all items with the .total_cost class. My previous recommendation was just a simple solution for people who don’t want to mess with code. If you do want to, try this out
<script>
function truncate(element) {
let number = parseFloat(element.innerText);
if (!isNaN(number)) { // only run if the text is a number
element.innerText = Math.trunc(number).toString(); // truncate the number
}
}
// function to run truncate on all elements with class 'total_cost'
function truncateAll() {
let elements = document.getElementsByClassName('total_cost');
for (let element of elements) {
truncate(element);
}
}
// Setup MutationObserver to keep watching for changes and truncate as necessary
let observer = new MutationObserver(truncateAll);
let config = { childList: true, subtree: true };
observer.observe(document.body, config);
// Call truncateAll immediately to truncate any numbers already on the page when the script runs.
truncateAll();
</script>
hi @jasonjkd glad to help. I have suggested that returned value will be in cents like values from Stripe (eg. $1 == 100) but I didn’t check it and forget to mentioned it. I see you have figure it out.
No need to be rude There is no “right” answer to anything, and setting a max width would achieve the desired effect without decreasing performance and in a way where no additional code needs to be messed with.
Don’t forget, you’re in a no-code community right now where people greatly appreciate simple solutions which don’t require code.
Sorry I didn’t meant to be rude as I use to be honest and saying truth. PEACE
I Agree with statement that there is 100 solutions for identical result, but this solution would not recommend even junior developer.
Arguing that this is a “no-code” is not reason giving such solution. BTW without custom code is WF toothless toy.
hi @jasonjkd you can give each item (text block) an attribute (as in previous example) to grab all text fields (cost_per_head , total_savings ) and do division directly to keep it one-liner.
@Stan everyones approach to solving problems are welcome, regardless of your personal opinion. Consistently being rude and dismissive (which you have a track record of) does not create an inclusive environment for those who are volunteering their valuable time to help others.
@Julian_Galluzzo I’m sorry you’re on the receiving end of this. Your contributions are appreciated.