Skip to content

Commit

Permalink
Add support for hx:validate
Browse files Browse the repository at this point in the history
  • Loading branch information
wimdeblauwe committed Aug 23, 2023
1 parent c84b09b commit 9d17796
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -51,6 +51,7 @@ public Set<IProcessor> 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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,12 @@ void testWithHxVals() throws Exception {
.containsPattern("hx-vals-div-number.*hx-vals=\"\\{&quot;someNumberProperty&quot;: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\"");
}
}
1 change: 1 addition & 0 deletions src/test/resources/templates/htmx-dialect-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<div id="hx-swap-div-with-null" hx:swap="${falseVariable}?'afterend':null"></div>
<div id="hx-swap-div-with-th-with" th:with="sum = ${1+1}" hx:swap="${sum.equals(2)}?'afterend':null"></div>
<div id="hx-target-div-with-th-each" th:each="number : ${listVariable}" hx:target="${number}"></div>
<div id="hx-validate-div" hx:validate="${trueVariable}"></div>
</body>
</html>

0 comments on commit 9d17796

Please sign in to comment.