Skip to content

Commit

Permalink
adding 'setvalue' and 'autofocus' attribtes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtylman committed Oct 18, 2018
1 parent 954765b commit 45124f3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 11 additions & 1 deletion element.go
Expand Up @@ -178,6 +178,11 @@ func (e *Element) GetID() string {
return val
}

//SetValue sets the 'value' attribute
func (e *Element) SetValue(val string) {
e.SetAttribute("value", val)
}

//SetID sets the `id` attribute
func (e *Element) SetID(id string) {
e.SetAttribute("id", id)
Expand All @@ -193,6 +198,11 @@ func (e *Element) Enable() {
e.RemoveAttribute("disabled")
}

//AutoFocus adds the auto-focus atribute to the element
func (e *Element) AutoFocus() {
e.SetAttribute("autofocus", "")
}

//Hide if set, will not render the element.
func (e *Element) Hide() {
e.Hidden = true
Expand All @@ -203,7 +213,7 @@ func (e *Element) Show() {
e.Hidden = false
}

//Find returns the kid, or offspring with a specific `id` attribute value.
//Find returns the kid, or offspring with a specific `id` attribute value.
func (e *Element) Find(id string) *Element {
if e.GetID() == id {
return e
Expand Down
18 changes: 17 additions & 1 deletion element_test.go
@@ -1,9 +1,10 @@
package gowd

import (
"github.com/stretchr/testify/assert"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestElement_SetAttributes(t *testing.T) {
Expand Down Expand Up @@ -62,3 +63,18 @@ func TestElement_Hide(t *testing.T) {
elem.RemoveElement(p)
testOuput(t, elem, "<div></div>")
}

func TestElement_SetValue(t *testing.T) {
elem := NewElement("div")
elem.SetValue("hoho")
assert.Equal(t, "hoho", elem.GetValue())
testOuput(t, elem, "<div id=\"_div1\" value=\"hoho\"></div>")
}

func TestElement_AutoFocus(t *testing.T) {
elem := NewElement("div")
_, exists := elem.GetAttribute("autofocus")
assert.False(t, exists)
elem.AutoFocus()
testOuput(t, elem, "<div id=\"_div1\" autofocus=\"\"></div>")
}

0 comments on commit 45124f3

Please sign in to comment.