File: select.go

package info (click to toggle)
mumax3 3.10-9
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 7,596 kB
  • sloc: makefile: 181; ansic: 155; sh: 77
file content (27 lines) | stat: -rw-r--r-- 701 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package gui

import "fmt"

type sel struct {
	data
}

func (e *sel) update(id string) []jsCall {
	return []jsCall{{F: "setSelect", Args: []interface{}{id, e.value()}}}
}

func (d *Page) SelectArray(id string, value string, options []string) string {
	return d.Select(id, value, options...)
}

func (d *Page) Select(id string, value string, options ...string) string {
	e := &sel{data: data{value}}
	d.addElem(id, e)
	html := fmt.Sprintf(`<select id=%v onchange="notifyselect('%v')" onfocus="notifyfocus('%v')" onblur="notifyblur('%v')"> `, id, id, id, id) + "\n"

	for _, o := range options {
		html += fmt.Sprintf(`<option value=%v> %v </option>`, o, o) + "\n"
	}
	html += `</select>`
	return html
}