1

I have 3 date fields into my list, but I want to disable one of them.

Column name = Fecha

I try to achieve it adding Script Editor like this:

enter image description here

Code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>

<script>
var itemID = $(" input[title='Fecha'] ").attr("id");



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



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



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



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

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

But it just don´t works, I try to debug it into new item view but I cant see code of script I insert into Script Editor, what is wrong there? Regards

2
  • You should wrap your code in $(document).ready(function{ ..Your code here.. }); then give a try.
    – Pradip R.
    Sep 1, 2017 at 5:25
  • It load correctly, but I get Uncaught ReferenceError: $ is not defined like Jquery is not loading @PradipR.
    – Ledwing
    Sep 1, 2017 at 5:40

1 Answer 1

2

Your js code does not run, because you have added Scrip Editor Web Part to the list view. If you want to disable field in New Item form, you have to modify Default New Form and add appropriate code there: Editing Default New Form

You can do same thing with Default Edit Form

3
  • Omg you´re right but now I get Uncaught ReferenceError: $ is not defined like Jquery is not loading
    – Ledwing
    Sep 1, 2017 at 5:43
  • I tried to recreate it but even I loaded exactly the same jquery file it just worked fine for me. What was the issue?
    – rafter13
    Sep 1, 2017 at 5:56
  • I create another question new issue in js code,
    – Ledwing
    Sep 1, 2017 at 5:58

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.