Hi everyone,
I'm trying to disable a lookup field and a number field using the following JavaScript code:
javascript
fd.field('{fieldName}').disabled = true;
However, I'm running into issues:
Lookup Field : The UI correctly shows the field as disabled, but the browser's developer console displays an error message.
Number Field : The UI does not disable the field at all, and the browser's developer console also shows an error message.
Is there a correct way to disable these types of fields via JavaScript? Any help or suggestions would be greatly appreciated.
Thanks!
StepanS
September 5, 2024, 10:30am
2
Hello @Ari_Gunawan ,
you can do a workaround if it throws up errors in console.
Add the ".disabled" class to your element - data field (Looku).
In JS
$(".disabled").prop("disabled",true)
But as I can see in documentation, it should also work with .disabled.
Regards
Stepan
Hello @Ari_Gunawan ,
Most probably the Lookup field is not fully loaded when the code is executed. Please use this code to disable Lookup field on form load:
fd.field('Field1').ready().then(function(field) {
fd.field('Field1').disabled = true;
});
Thanks @mnikitina !
You are correct. It might be because the lookup field is not fully loaded under fd.spRendered function.
Your workaround works for Lookup field.
However, the same approach doesn't seem to apply to the Number field.
@Ari_Gunawan ,
ready() function is required only for Lookup and Person or Group fields, Number field should work without it.
It works when I disable it on event handler (e.g. on click button).
However, it doesn't work when I disable it on fd.spRendered function:
fd.spRendered(function() {
if ({some logic}) {
fd.field('Amount').disabled = true;
}
});
I got below error message:
It looks like the Number field is not fully loaded as well on fd.spRendered function.
@Ari_Gunawan ,
Is this a complete code you have on the form? Please debug the code and comment out the line with the enable