diff options
| author | Shulhan <ms@kilabit.info> | 2023-05-05 18:21:07 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-05-05 18:21:07 +0700 |
| commit | c484bc6ec480dd799c491b3dd0f673f822c3b484 (patch) | |
| tree | f76ebab69a6840e280eb7d10df71a451faabc922 | |
| parent | 36a4816c921c2c52118ebe2ad9c9e39fe8e587a4 (diff) | |
| download | gorankusu-c484bc6ec480dd799c491b3dd0f673f822c3b484.tar.xz | |
all: add boolean Kind for FormInput, FormInputKindBoolean
The FormInputKindBoolean only used for convertion, for example
ToJsonObject.
In the WUI, it still rendered as string, not as checkbox.
FormInput with this Kind will be converted to true in ToJsonObject if
the Value is either "true", "yes", or "1".
| -rw-r--r-- | form_input.go | 9 | ||||
| -rw-r--r-- | key_form_input.go | 18 | ||||
| -rw-r--r-- | memfs_www_embed.go | 2 |
3 files changed, 25 insertions, 4 deletions
diff --git a/form_input.go b/form_input.go index 48ad067..5fd0a8d 100644 --- a/form_input.go +++ b/form_input.go @@ -5,9 +5,14 @@ package trunks type FormInputKind string +// List of valid value for field FormInput.Kind. const ( - FormInputKindNumber = "number" - FormInputKindString = "string" + // FormInputKindBoolean only used for convertion, for example + // ToJsonObject. + // In the WUI, it will be rendered as string. + FormInputKindBoolean = `boolean` + FormInputKindNumber = `number` + FormInputKindString = `string` ) // FormInput provide the information to create an input component. diff --git a/key_form_input.go b/key_form_input.go index 4922517..e457466 100644 --- a/key_form_input.go +++ b/key_form_input.go @@ -6,6 +6,7 @@ package trunks import ( "net/http" "net/url" + "strings" "github.com/shuLhan/share/lib/math/big" ) @@ -27,10 +28,25 @@ func (kfi KeyFormInput) ToHttpHeader() (headers http.Header) { } // ToJsonObject convert the KeyFormInput into JSON object. +// FormInput with Kind is FormInputKindBoolean will be converted to true if +// the Value is either "true", "yes", or "1". func (kfi KeyFormInput) ToJsonObject() (data map[string]interface{}) { + var ( + k string + fi FormInput + vstr string + ) + data = make(map[string]interface{}, len(kfi)) - for k, fi := range kfi { + for k, fi = range kfi { switch fi.Kind { + case FormInputKindBoolean: + vstr = strings.ToLower(fi.Value) + if vstr == `true` || vstr == `yes` || vstr == `1` { + data[k] = true + } else { + data[k] = false + } case FormInputKindNumber: data[k], _ = big.NewRat(fi.Value).Float64() default: diff --git a/memfs_www_embed.go b/memfs_www_embed.go index d279b37..12631b7 100644 --- a/memfs_www_embed.go +++ b/memfs_www_embed.go @@ -16,7 +16,7 @@ func generate__www() *memfs.Node { GenFuncName: "generate__www", } node.SetMode(2147484141) - node.SetModTimeUnix(1661400207, 805315661) + node.SetModTimeUnix(1683285123, 263412025) node.SetName("/") node.SetSize(0) node.AddChild(_memfsWWW_getNode(memfsWWW, "/doc", generate__www_doc)) |
