locked
It's possible to disable only the manual entry in the datetime field, but to choose the date using the button? RRS feed

  • Question

  • It's possible to disable only the manual entry in the datetime field, but to choose the date using the button?

     

    Wednesday, September 22, 2010 8:05 PM

Answers

  • Hi,

     

    If the button can be located on the toolbar, then the answer is 'yes' (if you want to have a button on the form, then you'd have to create a custom page and show it in the ifram). To add a buton on the toolbar that would set the date, in the OnLoad event of your form, set your field to disabled crmFor.all.yourfield.Disabled = true; and edit your isv.config to add the buton to your toolbar (here is the reference how to do that: http://msdn.microsoft.com/en-us/library/bb928136.aspx). The button should have the following code in the JavaScript attibute:

    crmForm.all.yourfield.Disabled = false;

    crmForm.all.yourfield.DataValue = new Date();

     

    I hope that helps,

    Kuba


    -- Kuba Skałbania, Netwise
    Wednesday, September 22, 2010 9:29 PM
  • Disabling dates in CRM works differently i.e. you need to disable the img tag associated with the control as well as the textbox, 

    please use this code to do the same (function on the OnLoad Event of form)

    USAGE:

    Example : - SetReadOnlyCrmDateField('dateofbirth', true)


    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 = "";
                }
            }
        }
    }

     

    Even though the date filed is readonly you can still set the DataValue programatically. But just have add some code to make sure that the disabled attribute gets saved on form save() .i.e. add the following code for the disabled field that you want to save

    crmForm.all.<attributename>.ForceSubmit()


    Hope this helps. Amar
    Saturday, September 25, 2010 2:06 PM

All replies

  • Hi,

     

    If the button can be located on the toolbar, then the answer is 'yes' (if you want to have a button on the form, then you'd have to create a custom page and show it in the ifram). To add a buton on the toolbar that would set the date, in the OnLoad event of your form, set your field to disabled crmFor.all.yourfield.Disabled = true; and edit your isv.config to add the buton to your toolbar (here is the reference how to do that: http://msdn.microsoft.com/en-us/library/bb928136.aspx). The button should have the following code in the JavaScript attibute:

    crmForm.all.yourfield.Disabled = false;

    crmForm.all.yourfield.DataValue = new Date();

     

    I hope that helps,

    Kuba


    -- Kuba Skałbania, Netwise
    Wednesday, September 22, 2010 9:29 PM
  • Disabling dates in CRM works differently i.e. you need to disable the img tag associated with the control as well as the textbox, 

    please use this code to do the same (function on the OnLoad Event of form)

    USAGE:

    Example : - SetReadOnlyCrmDateField('dateofbirth', true)


    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 = "";
                }
            }
        }
    }

     

    Even though the date filed is readonly you can still set the DataValue programatically. But just have add some code to make sure that the disabled attribute gets saved on form save() .i.e. add the following code for the disabled field that you want to save

    crmForm.all.<attributename>.ForceSubmit()


    Hope this helps. Amar
    Saturday, September 25, 2010 2:06 PM
  • Thank you for the information.
    Tuesday, October 5, 2010 2:21 PM