locked
Set field value and make field read only on custom list form RRS feed

  • Question

  • Thank you for looking at my post.

    A group is tracking "system" requests.  A system request can be a Suspected Bug, System Enhancement or Unknown.  As you can guess, for the most part the questions asked are similar, however there are very specific questions that would relate to a bug versus an enhancement.  So thinking about the newform.aspx.  I am not sure condistional formating would work as I don't want the form to continually have to reload itself and I am not even sure how I would do that.

    I came up with the idea of 3 individual pages with custom list forms on them.  I envision adding three links to the navigation, one to each form based on the request type.  That way I can choose which fields I want to display based upon the request type (linked page) they select.

    So the last thing to do is make sure that the request type field is given a value based upon the page they chose and then make that field read only so they can see what they selected but not change it.

    I did see that changing the ControlMode to "Display" will make the field readonly...and it works when tried it in editform.aspx....but since there is no value it reads "Request Type Field Value."  So the how do I push "Suspected Bug" or "System Enhancement" or "Unknown" to the Request Type field?

    Any suggestions or solutions would be greatly appreciated.  If there is a much simpler solution please do share that as well.  I know that if I ask the users to select the request type twice or if I leave all of the fields on the newform.aspx I will hear complaints.  Also, if the solution is to use Javascript or JQuery...I will be honest I am not a programmer, so I may need some extra instructions to implement.  Thank you VERY VERY much!!!

    Wednesday, May 15, 2013 10:22 PM

Answers

  • Hi,

    I will prefect jQuery. As you said you need extra instructions:

    1) Download SPservices jquery plugin from http://spservices.codeplex.com/downloads/get/636017

    2) unzip it and save .js file somewhere in your site in some doc library

    3) Lets create jquery now - This will involve some custom controls and queryString

    4) You are creating a drop down with all three types of request yo mentioned above (edit if required)

    5) Depending on what user has selected and click on buton a query string will be passed to your edit form page

    6) We will fetch the query string from URL and will autoselect this value in your request type field

    - Add a Content editor web part to a custom page and add this script as it is in source editor of this web part, the only thing you need to edit is your form URL.

    <div>
    <label for="RequestType" style="padding:0px 0px 10px 0px"><b>Request Type</b></label>
    <select name="RequestType" class="RequestType">
      <option value="Suspected Bug">Suspected Bug</option>
      <option value="System Enhancement">System Enhancement</option>
      <option value="Unknown">Unknown</option>
      
    </select>
    <button type="button" class="btn">Select Request</button>
    </div> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    function getParameterByName(name) 
    {   
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   
    var regexS = "[\\?&]"+name+"=([^&#]*)";   
    var regex = new RegExp( regexS );   
    var results = regex.exec( window.location.href );   
    if( results == null )     
    return "";   
    else     
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
    }
    		$(".btn").click(function(){    
    				var requestType=$(".RequestType").val(); 
    				
    				var url= '<your edit form URL>?request=' + requestType ;
    				window.location.href = url;
    		});
    });
    </script>

    Now this will redirect you to your new item form. We will now fetch querystring to AutoPopulate the Request type value and make it read only:

    Add a Content editor web part to a custom page and add this script as it is in source editor of this web part, the only thing you need to edit your field name if it is not "RequestType"

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script> 
    $(document).ready(function()
    {
    $("select[title$=RequestType]").attr('Value',getParameterByName('request'));
    $("select[title$=RequestType]").attr('disabled','true');
    function getParameterByName(name) 
    {   
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   
    var regexS = "[\\?&]"+name+"=([^&#]*)";   
    var regex = new RegExp( regexS );   
    var results = regex.exec( window.location.href );   
    if( results == null )     
    return "";   
    else     
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
    }
    }); 
    </script> 

    Hope this helps

    Let me know if you face any issues.

    Regards

    Ankur


    Please mark my answer if it helped you, I would greatly appreciate it.

    Thursday, May 16, 2013 6:01 AM

All replies

  • Hi,

    I will prefect jQuery. As you said you need extra instructions:

    1) Download SPservices jquery plugin from http://spservices.codeplex.com/downloads/get/636017

    2) unzip it and save .js file somewhere in your site in some doc library

    3) Lets create jquery now - This will involve some custom controls and queryString

    4) You are creating a drop down with all three types of request yo mentioned above (edit if required)

    5) Depending on what user has selected and click on buton a query string will be passed to your edit form page

    6) We will fetch the query string from URL and will autoselect this value in your request type field

    - Add a Content editor web part to a custom page and add this script as it is in source editor of this web part, the only thing you need to edit is your form URL.

    <div>
    <label for="RequestType" style="padding:0px 0px 10px 0px"><b>Request Type</b></label>
    <select name="RequestType" class="RequestType">
      <option value="Suspected Bug">Suspected Bug</option>
      <option value="System Enhancement">System Enhancement</option>
      <option value="Unknown">Unknown</option>
      
    </select>
    <button type="button" class="btn">Select Request</button>
    </div> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    function getParameterByName(name) 
    {   
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   
    var regexS = "[\\?&]"+name+"=([^&#]*)";   
    var regex = new RegExp( regexS );   
    var results = regex.exec( window.location.href );   
    if( results == null )     
    return "";   
    else     
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
    }
    		$(".btn").click(function(){    
    				var requestType=$(".RequestType").val(); 
    				
    				var url= '<your edit form URL>?request=' + requestType ;
    				window.location.href = url;
    		});
    });
    </script>

    Now this will redirect you to your new item form. We will now fetch querystring to AutoPopulate the Request type value and make it read only:

    Add a Content editor web part to a custom page and add this script as it is in source editor of this web part, the only thing you need to edit your field name if it is not "RequestType"

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script> 
    $(document).ready(function()
    {
    $("select[title$=RequestType]").attr('Value',getParameterByName('request'));
    $("select[title$=RequestType]").attr('disabled','true');
    function getParameterByName(name) 
    {   
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   
    var regexS = "[\\?&]"+name+"=([^&#]*)";   
    var regex = new RegExp( regexS );   
    var results = regex.exec( window.location.href );   
    if( results == null )     
    return "";   
    else     
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
    }
    }); 
    </script> 

    Hope this helps

    Let me know if you face any issues.

    Regards

    Ankur


    Please mark my answer if it helped you, I would greatly appreciate it.

    Thursday, May 16, 2013 6:01 AM
  • Hi h0mely,

    I think Ankur is providing a great help. When it comes to show and hide control, I always choose Jquery or javascript. It is easy to modify and maintain.

    Thanks,

    Entan Ming

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contacttnmff@microsoft.com.

    Entan Ming
    TechNet Community Support

    Thursday, May 16, 2013 7:05 AM
    Moderator