2
votes

I have a custom Edit form developed in SharePoint 2010. It contains a ListFieldIterator inserted with this markup:

<SharePoint:ListFieldIterator ID="Test" runat="server" ControlMode="Edit" />

It run correctly and when the form is displayed it show input fields, labels and description for each field of my list. Now I'm trying to migrate this form to SharePoint 2013 but it don't work. It render correctly field labels and descriptions, but input fields are not rendered. Instead I obtain empty span with this markup:

<span id="WPQ2d28b528a-a28d-45a6-8709-153c43078463Title" data-sp-options="{"mode":2,"source":"Title"}" data-sp-control="SPFieldText"></span>

If I try to insert a FormField in the custom form markup it will be rendered correctly. Problem seems to be related to ListFieldIterator. How can I fix this problem? Anyone can help me? Thanks,

Fabio

1

1 Answers

1
votes

For anyone else, this is the result of a good day of trial and error. This succesfully creates a form field and renders it. The gotcha is the DefaultValue part. Due to a bug - don't set that, you get an empty render string.

        int id = 1;
        FormField formField = new FormField();
        formField.ControlMode = SPControlMode.New;
        formField.ListId = SPContext.Current.List.ID;
        formField.FieldName = "Title";

        SPContext context = SPContext.Current;
        formField.RenderContext = context;
        formField.ItemContext = context;
        formField.ID = String.Format("ff1{0}", field.Id.ToString());


        StringWriter s = new StringWriter();
        HtmlTextWriter h = new HtmlTextWriter(s);

        formField.Value = field.DefaultValue;
        formField.RenderControl(h);



        //inputCell.Controls.Add(formField);
        inputCell.Controls.Add(new Literal() { Text = s.ToString() });