Skip to content

Commit

Permalink
Merge pull request #121 from gobuffalo/task-allowing-wrapper-class
Browse files Browse the repository at this point in the history
Allowing to specify the bootstrap form class
  • Loading branch information
paganotoni committed Sep 28, 2019
2 parents 106ac8f + 3db31b6 commit 721a1fb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions form/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func divWrapper(opts tags.Options, fn func(opts tags.Options) tags.Body) *tags.T
delete(opts, "errors")
}

if opts["bootstrap"] != nil {
bopts, ok := opts["bootstrap"].(map[string]interface{})
if ok {
divClass = bopts["form-group-class"].(string)
}

delete(opts, "bootstrap")
}

div := tags.New("div", tags.Options{
"class": divClass,
})
Expand Down
39 changes: 39 additions & 0 deletions form/bootstrap/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package bootstrap_test

import (
"testing"

"github.com/gobuffalo/tags"
"github.com/gobuffalo/tags/form/bootstrap"
"github.com/stretchr/testify/require"
)

func Test_BootstrapFormGroupClass(t *testing.T) {
r := require.New(t)
f := bootstrap.NewFormFor(struct{ Name string }{}, tags.Options{})

tcases := []struct {
options tags.Options
expected string
}{
{
expected: `<div class="form-group row"><label>Name</label><input class=" form-control" id="-Name" name="Name" type="text" value="" /></div>`,
options: tags.Options{
"bootstrap": map[string]interface{}{
"form-group-class": "form-group row",
},
},
},

{
expected: `<div class="form-group"><label>Name</label><input class=" form-control" id="-Name" name="Name" type="text" value="" /></div>`,
options: tags.Options{},
},
}

for _, tcase := range tcases {
l := f.InputTag("Name", tcase.options)
r.Equal(tcase.expected, l.String())
}

}
10 changes: 10 additions & 0 deletions form/checkbox_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func Test_Form_CheckboxTag_WithValue(t *testing.T) {
r.Equal(`<label><input name="Chubby" type="checkbox" value="1" checked /><input name="Chubby" type="hidden" value="2" /></label>`, ct.String())
}

func Test_Form_CheckboxTag_Checked(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
ct := f.CheckboxTag(tags.Options{
"checked": true,
"value": true,
})
r.Equal(`<label><input type="checkbox" value="true" checked /></label>`, ct.String())
}

func Test_Form_CheckboxTag_WithLabel(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
Expand Down

0 comments on commit 721a1fb

Please sign in to comment.