locked
Disabling a control prevents the value being saved RRS feed

  • Question

  • I am customising a SharePoint list form, whereby I have a content editor web part with a content link to a JavaScript file.

    The script contains the lines below to set the value of a field and disable the field. Both of these statements work as they should.

    When I select Save however, the value in the field does not get saved (the list item is saved, but this field is blank) - how can I fix this so that the value of the disabled field is saved into the SharePoint list?

    $("input[title='Description']").val("Test Value");
    $("input[Title='Description']").prop("disabled", true);	

    Monday, December 18, 2017 3:26 PM

Answers

  • Hi,

    You can set the inputbox to read Only instead of disable, when the inputbox is read Only, it can save the data, here is a code snippet for your reference:

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <script type="text/javascript">
    $( document ).ready(function() {
        $("input[title='Title']").val('test');
        $("input[title='Title']").prop('readOnly',true);
        $("input[title='Title']").css('background-color' , '#DEDEDE');
    });
    </script>
    

    It will display the input box with a read Only background color like below:

    Click saving, it will save data:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, December 19, 2017 8:09 AM

All replies

  • Hi,

    This is not supported in jquery

    https://sharepoint.stackexchange.com/questions/95623/why-is-jquery-saving-my-field-as-blank-when-i-set-the-field-to-disabled

    you can try the below

    https://community.nintex.com/thread/3186


    Please remember to click Mark as Answer on the answer if it helps you

    Monday, December 18, 2017 7:50 PM
  • In HTML forms, "disabled" elements will not be sent back to the server. "readonly" elements will be sent back to the server.

     

    <input type="text" disabled name="data1" value="will not be sent"/>
    
    <input type="text" readonly name="data2" value="will be sent"/>
    

     


    Mike Smith TechTrainingNotes.blogspot.com
    Books: SharePoint 2007 2010 Customization for the Site Owner, SharePoint 2010 Security for the Site Owner

    Tuesday, December 19, 2017 3:28 AM
  • Hi,

    You can set the inputbox to read Only instead of disable, when the inputbox is read Only, it can save the data, here is a code snippet for your reference:

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <script type="text/javascript">
    $( document ).ready(function() {
        $("input[title='Title']").val('test');
        $("input[title='Title']").prop('readOnly',true);
        $("input[title='Title']").css('background-color' , '#DEDEDE');
    });
    </script>
    

    It will display the input box with a read Only background color like below:

    Click saving, it will save data:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, December 19, 2017 8:09 AM
  • Hi,

     

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

     

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

     

    Thanks

     

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, December 21, 2017 9:56 AM
  • Hi,

    Again How is everything going ? Feel free to reply is you need any more help on this question.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Sunday, December 31, 2017 9:49 AM