I need to hide or show a datepicker field on a form based on permissions of a logged in user. However, the user may not log in until the form has already been displayed, so I can’t rely on setting the form configuration before it is displayed. Using the show() and hide() functions on a regular input field works, but I (usually, but not always) get the following error when using the show() function on a datePicker.
domvm.micro.js:1179 Uncaught TypeError: Cannot read properties of null (reading ‘_node’)
at alreadyAdopted (domvm.micro.js:1179:1)
at findSeqThorough (domvm.micro.js:1195:1)
at patchChildren (domvm.micro.js:1375:1)
at patch (domvm.micro.js:1246:5)
at patchChildren (domvm.micro.js:1376:1)
at patch (domvm.micro.js:1246:5)
at patchChildren (domvm.micro.js:1376:1)
at patch (domvm.micro.js:1246:5)
at patchChildren (domvm.micro.js:1376:1)
at patch (domvm.micro.js:1246:5)
Unfortunately I cannot create a snippet to demonstrate the issue or test it outside of my environment.
Here is the code I use to define the field when creating the form:
{type:"datePicker",id:"PromiseDate",label:"Promise Date",dateFormat:"%Y-%m-%d",labelPosition:"left",labelWidth:110,helpMessage:"This is the absolute drop-dead date as negotiated with the customer. Use this date when speaking with the customer.",
mark: function(d){
let today = new Date();
return (d.getFullYear() === today.getFullYear() && d.getMonth() === today.getMonth() && d.getDate() === today.getDate() ? "today" : "");
}
}
Here is the code I use for hiding/showing the field after the user logs in:
function showPromiseDate(){
let item = form.getItem("PromiseDate");
item.hide();
let ugrps = App.user?.groups || [];
for (var i=0;i<parseInt(ugrps.count);i++){
if (["sales","engineering"].indexOf(ugrps[i].toLowerCase()) !== -1){
dhx.awaitRedraw().then(()=>{ item.show(); });
}
}
}
Since similar methods work for other form controls such as input and select, I have a feeling it is due to the extra complexities the calendar adds to the datePicker. I’d ultimately like to see the show() function fixed for the datePicker, but if anyone has suggestions for other ways to hide and show a form field dynamically, I need to get around this issue quicker than the typical update release cycle.
I’m currently using version 8.3.3, but I’ve had this issue on a few different releases of 7.x and 8.x in the past in other projects.