Watz
04/26/2022, 5:26 PMcurRec.getField({ fieldId: 'phone' }).isMandatory = true
.
I know it won't validate them on save, but I have a check in saveRecord if it is mandatory and throw an error it is not filled out.
Running the code in the console works but not through the client script entry points.
Anyone has any solutions?
I would prefer not to add the asterisk through DOM manipulation. And it would be good if the field could hold it's isMandatory property itself.
According to this SA, isMandatory is read-only. But the help center does not state the same. And obviously it is not read-only on custom fields.Zoran R-DATAGRAM
04/26/2022, 5:39 PMWatz
04/26/2022, 5:44 PMZoran R-DATAGRAM
04/26/2022, 5:55 PMJustin B
04/26/2022, 6:46 PMvar phone = curRec.getField('phone');
phone.isMandatory = true;
Watz
04/26/2022, 6:49 PMFIELDS_TO_VALIDATE_FOR_MANDATORY.forEach(fieldId => {
const field = curRec.getField({ fieldId })
field.isMandatory = field.isDisplay
})
I've stepped through the code in the chrome debugger when it is executed and it looks good there, but nothing is happening.NElliott
04/29/2022, 8:57 AMWatz
04/29/2022, 9:18 AMWatz
04/29/2022, 9:20 AMconst SPECIAL_FIELDS_TO_VALIDATE_FOR_MANDATORY = {
[VENDOR.FIELDS.TAX_ID_NUM]: false,
[VENDOR.FIELDS.VAT_REG_NR]: false,
[VENDOR.FIELDS.DEFAULT_ADDRESS]: false,
}
const setFieldLabelRequired = (fldName: string, required: boolean): void => {
if (fldName) {
fldName = fldName.replace('inpt_', '')
fldName = fldName.replace('hddn_', '')
fldName = fldName.replace('_fs', '')
const label = document.getElementById(fldName + '_fs_lbl')
if (label) {
// Only add the asterisk to the first child label
if ((label.parentNode && label.parentNode.firstChild !== label) || (label.className && label.className.indexOf('uir-label-no-required-flag') !== -1)) {
return
}
const labels = label.getElementsByTagName('label')
let asteriskLabel
for (let i = 0; i < labels.length; i++) {
if (labels[i].className === 'uir-required-icon')
{
asteriskLabel = labels[i]
break
}
}
if (required && !asteriskLabel) {
asteriskLabel = document.createElement('label')
asteriskLabel.className = 'uir-required-icon'
asteriskLabel.textContent = '*'
label.appendChild(asteriskLabel)
}
else if (!required && asteriskLabel) {
label.removeChild(asteriskLabel)
}
}
}
}
Object.keys(SPECIAL_FIELDS_TO_VALIDATE_FOR_MANDATORY)
.forEach(fieldId => setFieldLabelRequired(fieldId, false))
Object.keys(SPECIAL_FIELDS_TO_VALIDATE_FOR_MANDATORY)
.filter(fieldId => SPECIAL_FIELDS_TO_VALIDATE_FOR_MANDATORY[fieldId])
.forEach(fieldId => setFieldLabelRequired(fieldId, true))