Skip to content

Commit

Permalink
Add formxxx attributes (for <input type="submit"> element) (#241)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
slegrand45 authored Feb 3, 2025
1 parent c366cfc commit ceb0e8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions html/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions html/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit ceb0e8e

Please sign in to comment.