From 9d17796f894687129de55238c59476f3f72372d3 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Wed, 23 Aug 2023 15:15:22 +0200 Subject: [PATCH] Add support for hx:validate --- .../io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialect.java | 3 ++- .../wimdeblauwe/hsbt/thymeleaf/HtmxDialectTest.java | 8 ++++++++ src/test/resources/templates/htmx-dialect-test.html | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialect.java b/src/main/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialect.java index 5dff8ee..65b6bcc 100644 --- a/src/main/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialect.java +++ b/src/main/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialect.java @@ -1,7 +1,7 @@ package io.github.wimdeblauwe.hsbt.thymeleaf; -import io.github.wimdeblauwe.hsbt.mvc.HtmxSpringStandardExressionObjectFactory; import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.wimdeblauwe.hsbt.mvc.HtmxSpringStandardExressionObjectFactory; import org.thymeleaf.dialect.AbstractProcessorDialect; import org.thymeleaf.dialect.IExpressionObjectDialect; import org.thymeleaf.expression.IExpressionObjectFactory; @@ -51,6 +51,7 @@ public Set getProcessors(String dialectPrefix) { htmxProcessors.add(new HtmxAttributeProcessor(dialectPrefix, "sync", mapper)); htmxProcessors.add(new HtmxAttributeProcessor(dialectPrefix, "target", mapper)); htmxProcessors.add(new HtmxAttributeProcessor(dialectPrefix, "trigger", mapper)); + htmxProcessors.add(new HtmxAttributeProcessor(dialectPrefix, "validate", mapper)); htmxProcessors.add(new HtmxAttributeProcessor(dialectPrefix, "vals", mapper)); htmxProcessors.add(new HtmxAttributeProcessor(dialectPrefix, "vars", mapper)); diff --git a/src/test/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialectTest.java b/src/test/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialectTest.java index 1026140..211ecc7 100644 --- a/src/test/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialectTest.java +++ b/src/test/java/io/github/wimdeblauwe/hsbt/thymeleaf/HtmxDialectTest.java @@ -129,4 +129,12 @@ void testWithHxVals() throws Exception { .containsPattern("hx-vals-div-number.*hx-vals=\"\\{"someNumberProperty":12345}\"") ; } + + @Test + void testHxValidate() throws Exception { + String html = mockMvc.perform(get("/htmx-dialect")) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + assertThat(html).containsPattern("hx-validate-div.*hx-validate=\"true\""); + } } diff --git a/src/test/resources/templates/htmx-dialect-test.html b/src/test/resources/templates/htmx-dialect-test.html index 6258ce2..ef3ef83 100644 --- a/src/test/resources/templates/htmx-dialect-test.html +++ b/src/test/resources/templates/htmx-dialect-test.html @@ -25,5 +25,6 @@
+