locked
So you've Disabled your Date Field.... Now bring it back to life!!! RRS feed

  • Question

  • Hi Chaps

    I've searched everywhere and I cannot find an answer for what seems an increadably simple task.

    I've disabled a date field on a form using the .Disabled method rather than .disabled (The Capital D, uses SDK method), but when I try to re-enabled the control by reversing the boolean value, only the Date-Picker button works.

    The date content remains disabled and/or read-only and I cannot enter a value within the box! How does one enabled a date control on a form that has previously been disabled???

    Cheers

    Steve

     

    Thursday, January 27, 2011 1:57 PM

Answers

  • There is a confirmed bug in CRM 4.0 (even up to R14) that if a DateTime-field is disabled in form customization it cannot be enabled through JavaScript. We have not received any information on when it would/could be fixed.

     

     

    • Marked as answer by lemonje Thursday, January 27, 2011 4:19 PM
    Thursday, January 27, 2011 4:17 PM
  • Hello Steve

     

    I have seen such kind of datetime behavior only once. Scenario:

    1. Control was set as readonly in field customization.

    2. Control was enabled using crmForm.all.<control id>.Disabled = false;

     

    Check this scenario please.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by lemonje Thursday, January 27, 2011 3:56 PM
    Thursday, January 27, 2011 3:24 PM
    Moderator

All replies

  • Could you paste your javascript code?
    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Thursday, January 27, 2011 2:04 PM
    Moderator
  • There is not much to it, which is why its so frustrating.

    To Disable: crmForm.all.new_mydate.Disabled = true;      // This works fine

    However to bring it back: crmForm.all.new_mydate.Disabled = false;

    This only enables the date-picker and not the actual control contents, meaning you cannot type in a date yourself, and the contents colour remains grey rather than black.

    Cheers

    Steve

    Thursday, January 27, 2011 2:51 PM
  • Well, I never seen this behavior before.

    Are you sure there is no other javascript that could interact with the page DOM?


    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Thursday, January 27, 2011 2:53 PM
    Moderator
  • No, its got me beat. I've been checking all our code and we have never tried to disable a date field before. They have always been required fields.

    So this is the first time we've tried to disable and then re-enabled a date control on a form. Surprising a that may sound. And I have to agree with you, I've never seen this behaviour before either, but its dam frustrating as its messing up my form validation code, because then I bring it back to life it doesn't think it has a date even though one has been selected with the date-picker element.

    Cheers

    Steve

    Thursday, January 27, 2011 3:19 PM
  • Hello Steve

     

    I have seen such kind of datetime behavior only once. Scenario:

    1. Control was set as readonly in field customization.

    2. Control was enabled using crmForm.all.<control id>.Disabled = false;

     

    Check this scenario please.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by lemonje Thursday, January 27, 2011 3:56 PM
    Thursday, January 27, 2011 3:24 PM
    Moderator
  • WOW, you're the man.

    That is exactly what was going on. Totally independent of this issue I decided to go back to the form designer and make all the fields enabled there and then disable them during form load event. I did this because of the workflow issue.

    Now the .Disabled = false is working correctly.

    You've got to love CRM for these quirks... Out of curiosity if a date field was disable on the form designer, is there any way to re-enable it?

    Cheers

    Steve

    Thursday, January 27, 2011 3:55 PM
  • Truly - I don't know =)

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, January 27, 2011 3:59 PM
    Moderator
  • There is a confirmed bug in CRM 4.0 (even up to R14) that if a DateTime-field is disabled in form customization it cannot be enabled through JavaScript. We have not received any information on when it would/could be fixed.

     

     

    • Marked as answer by lemonje Thursday, January 27, 2011 4:19 PM
    Thursday, January 27, 2011 4:17 PM
  • Hello I have the same problem. And I use a workaround:

     

    SetReadOnlyCrmDateField('new_datadeemissao', false);

     

    function SetReadOnlyCrmDateField(elementName, isReadOnly) {
        if (elementName != null) {
            var elem = document.getElementById(elementName + "img");
            if ((typeof (elem != "undefined")) && (elem != null)) {
                if (isReadOnly) {
                    elem.disabled = true;

                    // Also disable date text field
                    var node = elem.parentNode.previousSibling.firstChild;
                    node.disabled = true;
                    elem.src = '/_imgs/btn_dis_cal.gif';
                    node.className = "ro";

                }
                else {
                    elem.disabled = false;
                    var node = elem.parentNode.previousSibling.firstChild;
                    node.disabled = false;
                    elem.src = '/_imgs/btn_on_cal.gif';
                    node.className = "";
                }
            }
        }
    }

    Wednesday, June 29, 2011 8:15 PM
  • As long as you enable (uncheck the readonly box) on the form.  You should be able to enable/disable via javascript in the onload/onchange events just fine.  As mentioned earlier, this issue happens only when the field is initially configured as read-only.
    Wednesday, March 14, 2012 3:18 PM
  • Hi all,

    I have a Required Read-only field, because it gets his value from an event.

    In my javascript I have: 

    Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

    But it still allows me save the entity without fill in the field.

    I'm reading about and seems all people say this is the correct line of code, but I don't understand why is not working for me.

    Any sugestions?

    Thanks!


    Js



    • Edited by Gresziu_Dub Thursday, July 19, 2012 2:21 PM Better explanation
    Thursday, July 19, 2012 1:24 PM
  • Set the document.all.datefield.all.contentdisabled = false
    Tuesday, October 8, 2013 2:24 AM