1

I am working on a SharePoint On-Premises 2013 farm. and inside my Create & Edit form, i want to set a Status Choice field as read-only, then later on to chnage its value inside a JavaScript script.

Now i am using SPUtility.js to make my Status field as ReadOnly, as follow:-

SPUtility.GetSPFieldByInternalName('OrderStatus').MakeReadOnly();

But when i try to set its value inside my JavaScript as follow (so when user check a checkbox named "Order Start Working", to set the Status = "In Progress"):-

$('[id^="OrderStartWorking"][id$="RadioButtonChoiceField0"]').change(function(){
SPUtility.GetSPFieldByInternalName('OrderStatus').SetValue("In Progress");
});

OR using pure JavaScript appraoch:-

$('[id^="OrderStartWorking"][id$="RadioButtonChoiceField0"]').change(function(){
$('[id^="OrderStatus"]').val("In Progress");
});

the value did not change to "In Progress"

So I am not sure how i can set a value for a read-only choice list OR if i can remove the ReadOnly from my choice list >> then set its value = "In Progress" >> then make it as ReadOnly again. keeping in mind that i do not want to set the Status choice list as disabled using JavaScript, since in this case the value will not get submitted when i save the Edit/Create forms.

4
  • 1
    That’s what I do, I make it editable then set the value, then make it read only again.
    – mannaggia
    Feb 6, 2018 at 12:05
  • @mannaggia but how i can make a .MakeReadOnly() field editable again?is there a method inside SPUtility.js which support this?
    – John John
    Feb 6, 2018 at 16:57
  • 1
    Yes, .MakeEditable()
    – mannaggia
    Feb 7, 2018 at 0:16
  • @mannaggia .MakeEditable() it worked well for me
    – John John
    Feb 8, 2018 at 2:44

2 Answers 2

0

Read only fields aren't rendered on New/Edit form. Remove read only from choice list.

disable the field on form and set its value using jquery

$("#FieldId").prop("disabled", true);
$("#FieldId").val('valuetoset');
3
  • but i do not want to hide it, i want to make it ReadOnly so users can view the status, and inside my javascript i want to set the value of the ReadOnly list .. so for example when a user check a checkbox named "Start working" >> the ReadOnly list choice should be set to "In progress" automatically.. and so on..
    – John John
    Feb 6, 2018 at 11:50
  • Updated the original answer.
    – Deepmala
    Feb 6, 2018 at 12:37
  • but disabling the choice list will not post back the field when i submit my form,, as mentioned in my original question
    – John John
    Feb 6, 2018 at 16:57
0

As mentioned in @mannaggia comment.. MakeEditable() it worked well for me

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.