Dec 23, 2016
Mar 21, 2017
Core
Closed, Acceptance tests pass
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>(); }); }