Repository: maragudk/gomponents
Pull request #241 (2025-02-02 19:37:12)

Add formxxx attributes (for <input type="submit"> element)
Hello,

A small patch to add the following attributes:

- formaction
- formenctype
- formmethod
- formnovalidate
- formtarget

These attributes are useful in `<input type="submit">` element: [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/submit#additional_attributes)


markuswustenberg: Thanks! 😊
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/maragudk/gomponents/pull/241?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`033f6ac`)](https://app.codecov.io/gh/maragudk/gomponents/commit/033f6ac3c36da0e95882d2e00b8cdd54468d3050?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk) to head [(`e90000f`)](https://app.codecov.io/gh/maragudk/gomponents/commit/e90000f48ac0e2380d2d7c8246e81c75e6bb9800?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).
> Report is 32 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##              main      #241   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         5    -4     
  Lines          534       544   +10     
=========================================
+ Hits           534       544   +10     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/maragudk/gomponents/pull/241?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).


Patch:
diff --git a/html/attributes.go b/html/attributes.go
index e4cd796..6da541d 100644
--- a/html/attributes.go
+++ b/html/attributes.go
@@ -141,10 +141,30 @@ func For(v string) g.Node {
 	return g.Attr("for", v)
 }
 
+func FormAction(v string) g.Node {
+	return g.Attr("formaction", v)
+}
+
 func FormAttr(v string) g.Node {
 	return g.Attr("form", v)
 }
 
+func FormEncType(v string) g.Node {
+	return g.Attr("formenctype", v)
+}
+
+func FormMethod(v string) g.Node {
+	return g.Attr("formmethod", v)
+}
+
+func FormNoValidate() g.Node {
+	return g.Attr("formnovalidate")
+}
+
+func FormTarget(v string) g.Node {
+	return g.Attr("formtarget", v)
+}
+
 func Height(v string) g.Node {
 	return g.Attr("height", v)
 }


Test patch:
diff --git a/html/attributes_test.go b/html/attributes_test.go
index cfb64b5..9b668b2 100644
--- a/html/attributes_test.go
+++ b/html/attributes_test.go
@@ -21,6 +21,7 @@ func TestBooleanAttributes(t *testing.T) {
 		{Name: "controls", Func: Controls},
 		{Name: "defer", Func: Defer},
 		{Name: "disabled", Func: Disabled},
+		{Name: "formnovalidate", Func: FormNoValidate},
 		{Name: "loop", Func: Loop},
 		{Name: "multiple", Func: Multiple},
 		{Name: "muted", Func: Muted},
@@ -61,6 +62,10 @@ func TestSimpleAttributes(t *testing.T) {
 		{Name: "dir", Func: Dir},
 		{Name: "for", Func: For},
 		{Name: "form", Func: FormAttr},
+		{Name: "formaction", Func: FormAction},
+		{Name: "formenctype", Func: FormEncType},
+		{Name: "formmethod", Func: FormMethod},
+		{Name: "formtarget", Func: FormTarget},
 		{Name: "height", Func: Height},
 		{Name: "hidden", Func: Hidden},
 		{Name: "href", Func: Href},