0

I try to disable only one Date and Time field using jQuery using Script Editor

Html:

<td class="ms-dtinput">
<label for="Fechados_fb10b3d7-d448-474d-af75-13c64038c3e5_$DateTimeFieldDate" style="display:none">Fechados Date</label>
<input type="text" value="31/08/2017" maxlength="45" id="Fechados_fb10b3d7-d448-474d-af75-13c64038c3e5_$DateTimeFieldDate" title="Fechados" class="ms-input" autopostback="0">
</td>

First I try to disable using id of element as:

$("#Fechados_fb10b3d7-d448-474d-af75-13c64038c3e5_\\$DateTimeFieldDate").attr("readonly", true);

I don´t have any errors on console but field not disabled

enter image description here

I also try:

   <script>

    // Search for the input textbox of DatePicker by its title and get its Item ID 


    var itemID = $(" input[title='Fechados'] ").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');

    // 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>

but this line:

var itemID = $(" input[title='Fechados'] ").attr("id");

Always get

undefined

How can I achieve correctly it? Regards

  • Is hidding whole row an option for you? It may be easier to achieve this than to disable all inputs/icons – rafter13 Sep 1 '17 at 18:20
2

Did you try your code in document ready or outside?

$(document).ready(function() {
    $("input[title='Fechados']").attr("id");
});

Also, depending upon your jQuery version, it could be either .prop or .attr See: https://stackoverflow.com/questions/45170033/make-all-inputs-with-class-readonly

1

you can use sputility for hide/show any field in OOTB form.

Hide/Show field on list form based on value from another field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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