Question

I am currently using SharePoint 2010 and SPServices.js.

I am able to retrieve and update the value via SPServices when using regular HTML and ASP.NET server control values using SPServices.js and jQuery via the following code:

    $().SPServices({
        operation: method,
        async: false,
        listName: list,
        CAMLViewFields: fieldsToRead,
        CAMLQuery: query,
        completefunc: function (xData, Status) {
            $("#spinner").hide();
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                var myCustomField = ($(this).attr("ows_SQI"));
                var myCustomField2 = ($(this).attr("ows_SQIComments"));

                UpdateFields(myCustomField, myCustomField2);
            });
        }
    });

When the controls are the standard ASP.NET controls, i.e. <asp:TextBox> or a HTML textarea, SPServices can retrieve the values fine and jQuery updates them without any issues, however I recently changed these fields to a SharePointInputFormTextBox:

<SharePoint:InputFormTextBox ID="txtProgressNotes" Rows="18" Columns="120" RichText="true" RichTextMode="Compatible" AllowHyperlink="true" TextMode="MultiLine" runat="server"></SharePoint:InputFormTextBox>

Now jQuery no longer updates the value.

My question is, does SPServices support the retrieval of rich text and how are these fields updated via jQuery?

Was it helpful?

Solution 2

After digging deeper, it appears that SPServices is returning the value, and it appears jQuery is the actual problem of not updating the value retrieved from SharePoint when using rich text. I tried the following which did not originally work:

$("<%=txtProgressNotes.ClientID%>").val('Will not work');
$("<%=txtProgressNotes.ClientID%>").text('Will not work');
$("<%=txtProgressNotes.ClientID%>").html('Will not work');

The solution is to use the RTE_GetEditorDocument function:

 RTE_GetEditorDocument("<%=txtProgressNotes.ClientID%>").body.innerHTML = MDNotes;

This populates the textbox with the rich text from the SharePoint document library which is what I required. Hopefully this will help someone in the future as RTE_GetEditorDocument is not documented.

OTHER TIPS

Keep in mind that you're working client side here, so things are less "controls" at that point and more "collections of HTML elements and some script".

I can't tell for certain what operation you're using in your SPServices call, but I assume it's GetListItems from the rest of your code. When you make that call, SPServices uses AJAX to query the server for the list data. It doesn't do anything with the "controls" on the page.

When it comes to updating elements in the page, you can't assume anything with SharePoint (or any other Web application, frankly). Sometimes you can use the id like you're trying to do in your second comment, but with most field types, that isn't going to work because the "controls" render in more complex ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top