Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to make SharePoint DateTime field as Read only in NewForm.aspx?

I'm using the below script to make DateTimeColumn as read only. It's working fine in firefox & not in IE9.

Calendar icon onclick is not working in IE for date selection.

<script type="text/javascript" src="../../SiteAssets/jquery-1.9.0.js" />
<script>
$(document).ready(function () {
    $('input[title="DateTimeColumn"]').attr("disabled","disabled");
});
</script>
share|improve this question
    
What are you trying to accomplish? Are you wanting the field to not be there or be disabled? Are you still wanting to use the calendar dropdown? –  theChrisKent Feb 5 '13 at 19:14

1 Answer 1

If you only want to prevent the contents of the object from being changed, use the readOnly property instead of the disabled property:

$('input[title="DateTimeColumn"]').attr("readonly","readonly");

I strongly suggest do not use disabled attribute with DateTimeControl in SharePoint. It causes different behavior in browsers, see the explanation below.


The explanation why Calendar is loaded in FF, Chrome and is not loaded in IE

When Calendar icon is clicked the page that contains Calendar is loaded using Ajax request. See function clickDatePickerHelper in DatePicker.js file for more details.

Before the loading of Calendar the following checking is taking place:

 var f = document.getElementById(d);  // get input element for input element that contains Calendar value
 if (f != null && f.isDisabled)
      return;

Pay attention to the condition f.isDisabled here. Property isDisabled for element is always undefined in FF, Chrome but in IE it is defined depending on disabled attribute value for input element (for disabled it is true,for not disabled is false). It means that f != null && f.isDisabled always returns false no matter is input element attribute set to readonly or not in Chrome and FF


Differences between Disabled attribute and Read Only Attribute (source)

Key Differences

The Disabled attribute

  • Values for disabled form elements are not passed to the processor method. The W3C calls this a successful element.(This works similar to form check boxes that are not checked.)

  • Some browsers may override or provide default styling for disabled form elements. (Gray out or emboss text) Internet Explorer 5.5 is particularly nasty about this.

  • Disabled form elements do not receive focus.

  • Disabled form elements are skipped in tabbing navigation.

The Read Only Attribute

  • Not all form elements have a readonly attribute. Most notable, the , , and elements do not have readonly attributes (although thy both have disabled attributes)

  • Browsers provide no default overridden visual feedback that the form element is read only. (This can be a problem… see below.)

  • Form elements with the readonly attribute set will get passed to the form processor.

  • Read only form elements can receive the focus

  • Read only form elements are included in tabbed navigation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.