Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Ramstack.HtmxToolkit/HtmxFieldValues.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -82,6 +83,7 @@ public HtmxFieldValues(string[]? values) =>
/// <returns>
/// An <see cref="HtmxFieldValues" /> containing the specified values.
/// </returns>
[SuppressMessage("ReSharper", "UseCollectionExpression")]
public static HtmxFieldValues Create(ReadOnlySpan<string> values)
{
return values.Length switch
Expand All @@ -100,6 +102,7 @@ public static HtmxFieldValues Create(ReadOnlySpan<string> values)
/// <returns>
/// An <see cref="HtmxFieldValues" /> containing <paramref name="value" />.
/// </returns>
[SuppressMessage("ReSharper", "UseCollectionExpression")]
public static implicit operator HtmxFieldValues(string? value) =>
new(value);

Expand All @@ -110,6 +113,7 @@ public static implicit operator HtmxFieldValues(string? value) =>
/// <returns>
/// An <see cref="HtmxFieldValues" /> containing <paramref name="values" />.
/// </returns>
[SuppressMessage("ReSharper", "UseCollectionExpression")]
public static implicit operator HtmxFieldValues(string[]? values) =>
new(values);

Expand Down
10 changes: 5 additions & 5 deletions src/Ramstack.HtmxToolkit/wwwroot/htmx-toolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ document._r_htmx ||= ((document, htmx) => {

// HTMX reads hx-request from the element and its ancestors; the nearest value wins.
// Values computed with "js:" cannot be read without evaluating them, so they are skipped.
const no_headers = elt => {
const has_no_headers = elt => {
let result = false;
api.getClosestMatch(elt, e => {
let value = api.getAttributeValue(e, "hx-request")?.trim();
if (value && !/^(js|javascript):/.test(value)) {
try {
let { noHeaders } = JSON.parse(value[0] === "{" ? value : `{${value}}`);
if (noHeaders != null) {
result = !!noHeaders;
let no_headers = JSON.parse(value[0] === "{" ? value : `{${value}}`).noHeaders;
if (no_headers != null) {
result = !!no_headers;
return true;
}
}
Expand All @@ -189,7 +189,7 @@ document._r_htmx ||= ((document, htmx) => {
let elt = e.target;
let { xhr, target, select, requestConfig } = e.detail;

if (requestConfig.headers["HX-Request-Type"] == null && !no_headers(elt)) {
if (requestConfig.headers["HX-Request-Type"] == null && !has_no_headers(elt)) {
select ||= api.getClosestAttributeValue(elt, "hx-select");
let request_type = target === document.body || select && select !== "unset" ? "full" : "partial";
xhr.setRequestHeader("HX-Request-Type", request_type);
Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.HtmxToolkit/wwwroot/htmx-toolkit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading