1

I am trying to disable a textbox in SharePoint WSS3 and force a specific value (given by another JavaScript function) but I can't seem to find the right way of doing it. I have come across different issues. Let's say I have a normal single line text value named prova and another one named Description. Description is required, prova is not.

First Issue: If the field IS required, even if there is something in the textbox, SharePoint says otherwise and does not allow me to insert the entry.

$(document).ready(function(){
    //var value = someFunction(...);
    var value = "test";
    $("input[title='Description']").attr("disabled", "disabled");
    $("input[title='Description']").val(value);
});

enter image description here

Second Issue: If the field IS NOT required SharePoint doesn't say anything but it inserts a blank value instead of the one given.

$(document).ready(function(){
    //var value = someFunction(...);
    var value = "test";
    $("input[title='prova']").attr("disabled", "disabled");
    $("input[title='prova']").val(value);
});

enter image description here

enter image description here

I have a feeling that tells me that there is some kind of SharePoint JavaScript function somewhere that listens for KeyUp or something. I have really no idea what to do now...

EDIT: It looks like the problem is related to disabling the textbox, if I comment the line where I disable the textbox it works in both scenarios. Maybe if I catch the insert request I can re-enable the textbox before SharePoint do the actual post. No idea how to do it though...

tshepang
  • 12,111
  • 21
  • 91
  • 136
raz3r
  • 3,071
  • 8
  • 44
  • 66
  • 1
    Good question! I'm missing the information when you will receive the Sharepoint errors. Upon clicking "OK"? And just to summarize: When the field is required (SharePoint required), and you enter some data via JavaScript - SharePoint thinks there is no data in the field and doesn't save your field data? Can you show some more code? `.val(value)` looks correct to set field values: http://formsdesigner.blogspot.de/2013/04/getting-and-setting-sharepoint-form.html – Dennis G Oct 28 '13 at 10:59
  • Yes upon clicking OK, SharePoint thinks the textbox is empty. However it looks like problem is related to the disabled attribute, take a look at the edit I've done. EDIT: The code is really that simple, beside the function that gets the value ofcourse. – raz3r Oct 28 '13 at 11:03

1 Answers1

1

Your problem really is related to disabling the textbox first. By default disabled textboxes are not contained in the POST request in IE.

See this post: Disabled form inputs do not appear in the request or this one: how to save data by disabled text box?

What you actually want to do is set the readonly attribute of the field, not disable it (readonly="readonly"). The problem with that is that the readonly state sometimes looks the same as the default state, so you also have to add some CSS to make it look greyed out.

Community
  • 1
  • 1
Dennis G
  • 21,405
  • 19
  • 96
  • 133