none
Disabling a field in PDP with JavaScript problem RRS feed

  • Question

  • Hello,

    I am attempting to disable a field on PDP with JavaScript.  It works fine on page load, but after clicking 'Save', the field is enabled again.  Looking at the source of the page, I see function(bEnable) which looks to re-enable all of the fields after a save.  So, my question is how do I persist disabled fields through JavaScript across save clicks?  Thanks!  (JavaScript to disable field below:)

    <script type="text/javascript" language="Javascript"
    src="/PWA_01/SiteAssets/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" language="Javascript"
    src="/PWA_01/SiteAssets/jquery-ui.min.js"></script>
    <script>
    $(document).ready(function() {
        var element = $("input[title='Project Name']");
        $(element).prop("disabled", true);  
    });
    </script>

    Saturday, September 13, 2014 5:38 PM

All replies

  • Hi,

    Have you tried using onload instead of ready? Also, I've used in the past readOnly instead of disabled

    Paul

    Monday, September 15, 2014 2:21 PM
  • I ended up fixing by creating the below function:

    function DisableAfterSaveJSInjection(WPDPParts)
    {
        for (var i = 0; i < WPDPParts.length; i++)
        {
            if(typeof(WPDPParts[i].EnablePart) == "function")
            {
                var oldMethod = WPDPParts[i].EnablePart;
                WPDPParts[i].EnablePart = function(bEnable)
                {
                    var retVal = oldMethod.call(oldMethod, bEnable);
                    SetFields();
                    return retVal;
                }
            }
        }
    }

    Monday, September 15, 2014 5:18 PM