3

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?

2

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.

  • Thanks for your response. Yes the call is using GetListItems, I am also aware that at this point the controls are not being manipulated. I assumed that from changing a ASP.NET control to a SharePoint control jQuery would be able to find the element, since at the most underlying level they are still DOM elements with an ID, just encapsulated by the framework in a different manner. – Darren Sep 5 '13 at 7:49
  • Because of the way .NET and SharePoint render those controls, there's not as much consistency as you're hoping for. It's all over the map. You really need to inspect the elements with the IE Developer Tools, Firebug, etc., in order to figure out what to select. – Marc D Anderson Sep 5 '13 at 11:57
  • Yes I agree, it is kind of all over, rather tricky to work with. Already inspected the elements and the issue has been resolved. Thanks for your input. – Darren Sep 5 '13 at 11:58
  • Glad you got it working. These inconsistencies are things that .NET developers have been highly insulated from for years. Now that you're all starting to look into the DOMs, you're seeing what warts Microsoft hath wrought. – Marc D Anderson Sep 5 '13 at 15:38
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.