Table of Contents

Class HtmxV2Config

Namespace
Ramstack.HtmxToolkit.Configuration
Assembly
Ramstack.HtmxToolkit.dll

Represents the configuration for HTMX 2.x.

public sealed class HtmxV2Config : HtmxConfig
Inheritance
HtmxV2Config
Inherited Members

Constructors

HtmxV2Config()

Represents the configuration for HTMX 2.x.

public HtmxV2Config()

Properties

AddedClass

Gets or sets the added class. The HTMX default is htmx-added.

public string? AddedClass { get; set; }

Property Value

string

AllowEval

Gets or sets a value indicating whether the use of eval is allowed. The HTMX default is true.

public bool? AllowEval { get; set; }

Property Value

bool?

AllowNestedOobSwaps

Gets or sets a value indicating whether out-of-band swaps nested in the main response are processed. The HTMX default is true.

public bool? AllowNestedOobSwaps { get; set; }

Property Value

bool?

AllowScriptTags

Gets or sets a value indicating whether <script> tags should be processed in new content. The HTMX default is true.

public bool? AllowScriptTags { get; set; }

Property Value

bool?

AttributesToSettle

Gets or sets the attributes to settle during the settling phase. The HTMX default is ["class", "style", "width", "height"].

public string[]? AttributesToSettle { get; set; }

Property Value

string[]

DefaultFocusScroll

Gets or sets a value indicating whether the focused element should be scrolled into view. The HTMX default is false.

public bool? DefaultFocusScroll { get; set; }

Property Value

bool?

DefaultSettleDelay

Gets or sets the default settle delay in milliseconds. The HTMX default is 20.

public int? DefaultSettleDelay { get; set; }

Property Value

int?

DefaultSwapDelay

Gets or sets the default swap delay in milliseconds. The HTMX default is 0.

public int? DefaultSwapDelay { get; set; }

Property Value

int?

DefaultSwapStyle

Gets or sets the default swap style. The HTMX default is InnerHtml.

[JsonConverter(typeof(HtmxSwapJsonConverter))]
public HtmxSwap? DefaultSwapStyle { get; set; }

Property Value

HtmxSwap?

DisableInheritance

Gets or sets a value indicating whether attribute inheritance is disabled. The HTMX default is false.

public bool? DisableInheritance { get; set; }

Property Value

bool?

DisableSelector

Gets or sets the selector for elements that HTMX must not process. The HTMX default is [hx-disable], [data-hx-disable].

public string? DisableSelector { get; set; }

Property Value

string

GetCacheBusterParam

Gets or sets a value indicating whether GET requests use a cache-busting parameter. The HTMX default is false.

public bool? GetCacheBusterParam { get; set; }

Property Value

bool?

GlobalViewTransitions

Gets or sets a value indicating whether the View Transition API should be used for swaps. The HTMX default is false.

public bool? GlobalViewTransitions { get; set; }

Property Value

bool?

HistoryCacheSize

Gets or sets the size of the history cache. The HTMX default is 10.

public int? HistoryCacheSize { get; set; }

Property Value

int?

HistoryEnabled

Gets or sets a value indicating whether HTMX history support is enabled. The HTMX default is true.

public bool? HistoryEnabled { get; set; }

Property Value

bool?

HistoryRestoreAsHxRequest

Gets or sets a value indicating whether history cache-miss requests are marked as HTMX requests. The HTMX default is true.

public bool? HistoryRestoreAsHxRequest { get; set; }

Property Value

bool?

Remarks

Available since HTMX 2.0.5.

IgnoreTitle

Gets or sets a value indicating whether document titles found in new content are ignored. The HTMX default is false.

public bool? IgnoreTitle { get; set; }

Property Value

bool?

IncludeIndicatorStyles

Gets or sets a value indicating whether the indicator styles are loaded. The HTMX default is true.

public bool? IncludeIndicatorStyles { get; set; }

Property Value

bool?

IndicatorClass

Gets or sets the indicator class. The HTMX default is htmx-indicator.

public string? IndicatorClass { get; set; }

Property Value

string

InlineScriptNonce

Gets or sets the nonce added to inline scripts. The HTMX default is an empty string.

public string? InlineScriptNonce { get; set; }

Property Value

string

InlineStyleNonce

Gets or sets the nonce added to inline styles. The HTMX default is an empty string.

public string? InlineStyleNonce { get; set; }

Property Value

string

MethodsThatUseUrlParams

Gets or sets the HTTP methods that use URL parameters. The HTMX default is ["get", "delete"].

[JsonConverter(typeof(HttpVerbArrayJsonConverter))]
public HttpVerb[]? MethodsThatUseUrlParams { get; set; }

Property Value

HttpVerb[]

RefreshOnHistoryMiss

Gets or sets a value indicating whether a history miss causes a full-page refresh instead of an AJAX request. The HTMX default is false.

public bool? RefreshOnHistoryMiss { get; set; }

Property Value

bool?

ReportValidityOfForms

Gets or sets a value indicating whether form validity is reported before a request is issued. The HTMX default is false.

public bool? ReportValidityOfForms { get; set; }

Property Value

bool?

Remarks

Available since HTMX 2.0.7.

RequestClass

Gets or sets the request class. The HTMX default is htmx-request.

public string? RequestClass { get; set; }

Property Value

string

ResponseHandling

Gets or sets the rules that determine how HTTP response status codes are handled.

public IList<ResponseHandlingConfig>? ResponseHandling { get; set; }

Property Value

IList<ResponseHandlingConfig>

Examples

options.UseHtmxV2(config =>
{
    // Assigning the list replaces the HTMX defaults, so the rules repeat them
    // and add one more: swap validation forms returned with status 422.
    config.ResponseHandling =
    [
        new() { Code = "204", Swap = false },
        new() { Code = "[23]..", Swap = true },
        new() { Code = "422", Swap = true, Error = false },
        new() { Code = "[45]..", Swap = false, Error = true }
    ];
});

ScrollBehavior

Gets or sets the scrolling behavior used by the show modifier of hx-swap. The HTMX default is Instant.

[JsonConverter(typeof(HtmxScrollBehaviorJsonConverter))]
public HtmxScrollBehavior? ScrollBehavior { get; set; }

Property Value

HtmxScrollBehavior?

ScrollIntoViewOnBoost

Gets or sets a value indicating whether boosted targets are scrolled into the viewport. The HTMX default is true.

public bool? ScrollIntoViewOnBoost { get; set; }

Property Value

bool?

SelfRequestsOnly

Gets or sets a value indicating whether requests are restricted to the current origin. The HTMX default is true.

public bool? SelfRequestsOnly { get; set; }

Property Value

bool?

SettlingClass

Gets or sets the settling class. The HTMX default is htmx-settling.

public string? SettlingClass { get; set; }

Property Value

string

SwappingClass

Gets or sets the swapping class. The HTMX default is htmx-swapping.

public string? SwappingClass { get; set; }

Property Value

string

Timeout

Gets or sets the request timeout, in milliseconds. The HTMX default is 0.

public int? Timeout { get; set; }

Property Value

int?

TriggerSpecsCacheEnabled

Gets or sets a value indicating whether parsed trigger specifications use a never-clearing cache. The cache is disabled by default.

[JsonConverter(typeof(HtmxTriggerSpecsCacheJsonConverter))]
[JsonPropertyName("triggerSpecsCache")]
public bool? TriggerSpecsCacheEnabled { get; set; }

Property Value

bool?

WithCredentials

Gets or sets a value indicating whether credentials are included in cross-origin requests. The HTMX default is false.

public bool? WithCredentials { get; set; }

Property Value

bool?

WsBinaryType

Gets or sets the type of binary data received over WebSocket connections. The HTMX default is Blob.

[JsonConverter(typeof(HtmxBinaryTypeJsonConverter))]
public HtmxBinaryType? WsBinaryType { get; set; }

Property Value

HtmxBinaryType?

Remarks

Requires the HTMX WebSocket extension.

Methods

Serialize()

Serializes this configuration to a JSON string.

protected override string Serialize()

Returns

string

A JSON string representing this configuration.