diff --git a/element.go b/element.go index 7432398..9bf7e26 100644 --- a/element.go +++ b/element.go @@ -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) @@ -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 @@ -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 diff --git a/element_test.go b/element_test.go index cc693b6..9de7c74 100644 --- a/element_test.go +++ b/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) { @@ -62,3 +63,18 @@ func TestElement_Hide(t *testing.T) { elem.RemoveElement(p) testOuput(t, elem, "
") } + +func TestElement_SetValue(t *testing.T) { + elem := NewElement("div") + elem.SetValue("hoho") + assert.Equal(t, "hoho", elem.GetValue()) + testOuput(t, elem, "
") +} + +func TestElement_AutoFocus(t *testing.T) { + elem := NewElement("div") + _, exists := elem.GetAttribute("autofocus") + assert.False(t, exists) + elem.AutoFocus() + testOuput(t, elem, "
") +}