Issues Disabling Lookup and Number Fields via JavaScript

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:

  1. Lookup Field: The UI correctly shows the field as disabled, but the browser's developer console displays an error message.
  2. Number Field: The UI does not disable the field at all, and the browser's developer console also shows an error message.

image

Is there a correct way to disable these types of fields via JavaScript? Any help or suggestions would be greatly appreciated.

Thanks!

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.
image

@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:
image

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