is there a way which i can set a field to mandatory using custom html?
I was wondering if there is a way to set a field to "Mandatory" if the section is visible. This needs to be set before any submission occurs, so I think the only way is to use custom HTML.
The built-in visibility control for DX7 cannot be set because it does not support the relational operator(greater than or less than), so I managed to create a custom HTML to show the hide section. Because this was done via custom, if a submission was done without the section visible, it shows "Validation Error." If I remove this mandatory checkbox, then the submission was successful.
Below is my custom HTML code. "Section 9" is the section that shows hide; within this section there is a select box field, which I wish to set to mandatory if visible via vice versa.
<script>
$(document).ready(function() {
// Function to remove mandatory attribute from fields in a specific section
function removeMandatory() {
var section = $('#section9'); // Target the specific section
// Find all input fields, selects, and textareas within the section
section.find('input, select, textarea').each(function() {
$(this).prop('required', false); // Remove the required attribute
console.log("Removed mandatory requirement from: " + $(this).attr('name')); // Log the removal
});
}
// Function to add mandatory attribute back to fields in a specific section
function addMandatory() {
var section = $('#section9'); // Target the specific section
// Find all input fields, selects, and textareas within the section
section.find('input, select, textarea').each(function() {
$(this).prop('required', true); // Add the required attribute
console.log("Added mandatory requirement to: " + $(this).attr('name')); // Log the addition
});
}
// Function to check gtotalCur and toggle section visibility
function checkSectionVisibility() {
var gtotalCur = parseFloat($('input[name="gtotalCur"]').val().replace(/,/g, '')) || 0;
if (gtotalCur >= 10000) {
$('#section9').show(); // Show section9 if gtotalCur >= 10000
addMandatory(); // Add mandatory attributes back
} else {
$('#section9').hide(); // Hide section9 if gtotalCur < 10000
removeMandatory(); // Remove mandatory attributes
}
}
// Initial check on page load
checkSectionVisibility();
// Listen for changes on gtotalCur input field
$('input[name="gtotalCur"]').on('input change', function() {
checkSectionVisibility();
});
});
</script>
Thank you in advance