XForm add Table Class - Episerver 6 R2

Vote:
 

Hi,

Is it possible to add a class to the XForm table element so it could look like:

Is there any C# code I can add or is there a place where the basic shell f the form is created?

I can do it through JQuery but I would like to do it as the form renders as I need to run a ScreamingFrog Index across the site to look for this class and i think using JQuery would not kick in.

Thanks

Jon

#190462
Apr 11, 2018 11:51
Vote:
 

Hi Jonathan,

There is a way you can do this when you create the forms by modifying the form markup. If you open the XForms editor on the appropriate form and press [ctrl][shift][c], the HTML of the form will be copied to your clipboard (though this may only work on older versions of IE). You can then modify the code in a text editor, copy it back to the clipboard then go back in to the XForms editor and press [ctrl][shift][v] to paste the code back in.

Alternatively, if you're after a way to do this programmatically when the form is rendered, you'll need to tie in to the XFormControl.ControlsCreated event in your global.asax. In your event handler you can access the controls that make up the XForm and, as I recall, the opening table tag is included in a LiteralControl so you can modify its contents something like this:

private void XFormControlsCreated(object sender, EventArgs e)
{
    XFormControl formControl = (XFormControl)sender;
    ControlCollection controls = formControl.Controls;
    foreach (var control in controls)
    {
        var literalControl = control as LiteralControl;
        if (literalControl != null)
        {
            literalControl.Text = literalControl.Text.Replace("id=\"id_matrix\"", "id=\"id_matrix\" class=\"mytable\"");
        }
    }
}

Just as an advanced warning, I don't have an instance of a V6 site running to test this so I can't guarantee it works as-is but hopefully it should give you a good start.

#190518
Apr 11, 2018 15:32
Vote:
 

Hi, Your second option works a treat - thank you so much,

Jon

#190524
Edited, Apr 11, 2018 15:49
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.