Try our conversational search powered by Generative AI!

Ability to fallback to a non-JS version per visitor (BETA)

Found in

EPiServer.Forms 4.2.1

Fixed in

EPiServer.Forms 4.4.4

(Or a related package)

Created

Dec 23, 2016

Updated

Mar 21, 2017

Area

Core

State

Closed, Acceptance tests pass


Description

This story introduces a new service class, WorkingModeService, to determine if the Forms add-on works in non-js mode. The default implementation returns settings from the Forms.config file.

A developer can override the IsWorkingInNonJSMode method to decide when Forms should work in non-js mode for each request. Below is an example that demonstrates how Forms work without JavaScript (enable non-js mode) for all visitors using an old IE browser:

public class CustomJSWorkingModeService: WorkingModeService
{
        public override bool IsWorkingInNonJSMode(FormIdentity formIden, HttpContextBase httpContext)
        {
            if (httpContext.Request.UserAgent.Contains("Trident/4.0"))    // old IE browser
            {
                return true;
            }
 
            return base.IsWorkingInNonJSMode(formIden, httpContext);
        }
}

Use the Config DI container to use your class instead of default one in an initialize module, like the example below:

public void ConfigureContainer(ServiceConfigurationContext serviceConfigurationContext)
{
                _serviceConfigurationContext = serviceConfigurationContext;
 
                serviceConfigurationContext.Services.Configure(
                    c =>
                    {
                        c.For<WorkingModeService>().Use<CustomJSWorkingModeService>();
                    });
}