1

Into NewForm.aspx I have Date and Time field, which I disabled via jQuery.

My computer is set to 14:46, so I will receive 14:45 in SharePoint. Hour is correct but minutes are not; it is always set as 00.

Column Setting

List column settings

Field in NewForm.aspx

Field in NewForm.aspx dialog

JS to disable date and time column

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
     var itemID = $("input[title='Fecha']").attr("id");

// Trim the Item ID and keep the first part which is common for each element of this DatePicker

    var itemCode = itemID.substring(0, itemID.indexOf('$'));

    // Set text input to readOnly  

    $( "[id^=" + itemCode + "] td.ms-dtinput > input[id$='Date']" ).attr('readonly', 'readonly');


    $( "[id^=" + itemCode + "] td.ms-dtinput > input[id$='Date']" ).attr('disabled', 'disabled');

    // Disable the onclick action on the button

    $( "[id^=" + itemCode + "] td.ms-dtinput > a" ).attr('onclick','').unbind('click');

    // Disable the 2 time select elements

    $( "[id^=" + itemCode + "] td.ms-dttimeinput > select[id$='DateHours']" ).attr('disabled', 'disabled');

    $( "[id^=" + itemCode + "] td.ms-dttimeinput > select[id$='DateMinutes']" ).attr('disabled', 'disabled');

});

</script>

Regards.

1 Answer 1

2

If you instead use the calculated value default value option, and set it to NOW(), this will set the date, plus hour and time. Keep in mind the hour may not match your local time, based on your time zone settings, but I just confirmed the use of now() will set the minute value correctly.

Cheers, Matt

enter image description here

1
  • Best solution, I was thinking about set something like DateTime.Now.Utc with javascript, but your solution is the best
    – Ledwing
    Sep 1, 2017 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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