Forum Discussion

lpignedoli's avatar
lpignedoli
Ideator II
9 years ago

Disable date and Item in Form

Hi, I have a form with an field type="Date" (Name=expiring_date) and another field type="Item" (Name=item_code). I would disable during the OnFormPolulated event if the state is different from released. I tried: document.getElementsByName("expiring_date")[0].disabled=true; or getFieldByName("expiring_date").disabled = true; But doesn't work. Any suggestion? Thanks

2 Replies

  • Hello, The getFieldByName method does not return the input of the field, but rather the containing <div> element of the field. In order to prevent a user from editing a field, you will need to run code similar to the following sample to disable all of the inputs of the field.
    // Disable all inputs of a date property.
    var inputs = getFieldByName("test_date").getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++)
    {
    inputs.disabled = true;
    }
    
    // Disable all inputs of an Item property.
    // I needed to wrap this code inside of a timeout to work around an issue where the field was not being disabled
    setTimeout(function(){
    
    // Disable the text field of the Item property
    var inputs2 = document.getElementsByName("test_item")[0].getElementsByTagName("input");
    for (var i = 0; i < inputs2.length; i++)
    {
    inputs2.disabled = true;
    }
    
    // Disable the ellipsis button that launches the search dialog
    var button = document.getElementsByName("test_item")[0].getElementsByTagName("button")[0].disabled = true;
    }, 0);
    This sample was written to be run from an onFormPopulated Form Event. Chris _______________________ Christopher Gillis Aras Labs Software Engineer