Date field not get disabled

Hi,

I am trying to disable date field when item is locked, I did something like this:

Method is hooked on form event "OnFormpopulated"

var isItemLocked = thisItem.isLocked();

var transfer_date = getFieldByName("transfer_date");

if(isItemLocked)
{

       transfer_date.getElementsByTagName("input")[0].disabled = true;
       transfer_date.getElementsByTagName("input")[1].disabled = true;
       transfer_date.getElementsByTagName("input")[1].src = "../images/calendar-disabled.svg";

}

Reference from : gist.github.com/.../bb83b790e66d1977eeb09b1769c5a61c

so, when I locked item then date field won't get disabled, and if I unlock it and again lock it then it works fine i.e date field gets disabled.

I debug the code but the behavior is same when Item is locked first time and second time.

I tried this on IE, Chrome and Firefox but the got same results.

Regards,

Maddy.

  • Hi Maddy

    Did you tried using the time out option. Try tweaking around the time out value (here it is 200)  and increase or decrease depends on the performance of your environment.


    var isItemLocked = thisItem.isLocked();

    var transfer_date = getFieldByName("transfer_date");

    disableDateField = function() {
    if(isItemLocked)
    {
    transfer_date.getElementsByTagName("input")[0].setAttribute("disabled", "");
    transfer_date.getElementsByTagName("input")[1].setAttribute("disabled", "");
    transfer_date.getElementsByTagName("input")[1].src = "../images/calendar-disabled.svg";
    }};
    setTimeout(disableDateField, 200);

    It works well in my environment

    Thank You

    Gopi

  • Thank you !  @Gopi .. It's working now..

    but what is the purpose of this setting timeout?

  • Hi Maddy

    Timeout will allows a function to be called after a certain number of milliseconds has passed. In this case the function will be called after 200 milliseconds (Allowing the browser page to load and calling the function to disable the field)

    Thanks

    Gopi