This project has moved. For the latest updates, please go here.

Date Field Read Only

Mar 4, 2015 at 11:35 AM
Edited Mar 4, 2015 at 11:39 AM
Hello,

I want to set a date field „Read only“. Unfortunately this field is empty and read only although it contains a date. My code is:
      <script type="text/javascript" src="/…./jquery-1.11.2.min.js"></script>
      <script type="text/javascript" src="/…./sputility.min.js"></script>
     <script type="text/javascript">
       $(document).ready(function() {

      SPUtility.GetSPFieldByInternalName("DueDate").MakeReadOnly();
          };</script       


I tried to make another field read only, whose type is number and it runs. Is it not possible to set date fields read only?
Coordinator
Mar 5, 2015 at 12:08 AM
Sorry to hear you are having issues. Date fields are supported.

Can you give me some more information:
  1. What version of SharePoint?
  2. What browser are you using?
  3. This is a date only field correct?
  4. Are you using 12hr or 24hr format?
Mar 5, 2015 at 6:39 AM
First of all Thanks for your answer!
  1. SharePoint 2013 Foundation
  2. Internet Explorer 11
  3. I am sure that this field is correct. I use a lot of date fields and tried everys field to set read only. Unfourtanetly it did not work on any field.
  4. 24hr Format
I hope this Information will help you.
Mar 5, 2015 at 8:55 AM
I changed the type to Date&Time and was suprised that the time is readonly but the date is still "away".....
Coordinator
Mar 5, 2015 at 11:07 PM
Since you are using the 24HR date format, you'll need to call SetTimeFormat before the rest of your code.

For example:
<script type="text/javascript">
$(document).ready(function() {
    SPUtility.SetTimeFormat('24HR');
    SPUtility.GetSPFieldByInternalName("DueDate").MakeReadOnly();
};
</script>
Mar 6, 2015 at 8:09 AM
Same Problem with this code... :(

Can it be possibly that i have to Change the date Format like "SPUtility.SetTimeFormat('DD.MM.YYYY);" ???
I am form Germany and use this date Format (DD.MM.YYYY; example: 31.12.2014)
I can imagine that there are Problems with the different time formats DD.MM.YYYY and MM.DD.YYYY !?!?!
Coordinator
Mar 6, 2015 at 9:05 PM
Ah yes the date separator is probably the issue.

I'll take a look at making the date separator customizable. I've logged a new issue on github:
https://github.com/kitmenke/sputility/issues/13
Mar 10, 2015 at 9:27 AM
Thanks for your answer Kit!

I am sorry but i am not a SP or programming and unfortunately i do not know what i have to do to use your issue....
Should i donwload your sputility.js again ?!?! Or what i have to do to use readonly for date types?
Coordinator
Mar 11, 2015 at 3:36 AM
Edited Mar 11, 2015 at 3:37 AM
I logged the issue because I wasn't sure when I would get time to work on it. :) Luckily, I did get some time and it should be fixed in SPUtility.js 0.11.2. I added the ability to set the date separator. Can you please download the latest version of SPUtility.js?

Also, we'll need to tweak your code a bit:
<script type="text/javascript">
$(document).ready(function() {
    SPUtility.SetTimeFormat('24HR');
    SPUtility.SetDateSeparator('.');
    SPUtility.GetSPFieldByInternalName("DueDate").MakeReadOnly();
};
</script>
Marked as answer by Llorente on 3/11/2015 at 6:29 AM
Mar 11, 2015 at 8:31 AM
IT WORKS! Great! A huge thank you for your work Kit!