Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top