I’m using Airtable data to affect block visibility. When a user perform some action, AT formulas will update and determine new block visiblity parameters. Here’s the script :
<script>
// Configuration affichage
document.addEventListener('DOMContentLoaded', function() {
// Configuration array where each item represents a field and the associated block to manage
const conditions = [
{
field: 'Afficher Invitation',
blockId: 'invit1'
},
{
field: 'Afficher Invitation',
blockId: 'invit2'
}
// Add more conditions as needed
];
conditions.forEach(condition => {
// Retrieve the field value from the logged in user data
let fieldValue = window['logged_in_user'][condition.field];
// Determine whether to hide the block based on the field value
let shouldHide = fieldValue != 1; // Hides if the value is not 1
// Hide or show the block based on the shouldHide flag
let block = document.getElementById(condition.blockId);
if (block) {
block.style.display = shouldHide ? 'none' : '';
}
});
});
//Events listeners -> Recharger certaines parties de la page
document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('update-record-success-invit2', () => {
window.location.reload();
});
});
</script>
This only works on occasion. Is there a better way to refresh the user data ? Airtable should be returning the newly calculted formula values to Softr.