Пример #1
0
Файл: string.go Проект: kego/ke
func (v *StringEditorView) Render() *vecty.HTML {

	contents := vecty.List{
		prop.Value(v.model.Node.ValueString),
		prop.Class("form-control"),
		event.KeyUp(func(e *vecty.Event) {
			getVal := func() interface{} {
				return e.Target.Get("value").String()
			}
			val := getVal()
			changed := func() bool {
				return val != getVal()
			}
			go func() {
				<-time.After(common.EditorKeyboardDebounceShort)
				if changed() {
					return
				}
				v.App.Dispatch(&actions.Modify{
					Undoer:  &actions.Undoer{},
					Editor:  v.model,
					Before:  v.model.Node.NativeValue(),
					After:   val,
					Changed: changed,
				})
			}()
		}),
	}

	if sr, ok := v.model.Node.Rule.Interface.(*system.StringRule); ok && sr.Long {
		v.input = elem.TextArea(
			contents,
		)
	} else {
		v.input = elem.Input(
			prop.Type(prop.TypeText),
			contents,
		)
	}

	return elem.Div(v.input)
}
Пример #2
0
Файл: number.go Проект: kego/ke
func (v *NumberEditorView) Render() *vecty.HTML {

	v.input = elem.Input(
		prop.Type(prop.TypeNumber),
		prop.Value(fmt.Sprintf("%v", v.model.Node.ValueNumber)),
		prop.Class("form-control"),
		event.KeyUp(func(e *vecty.Event) {
			getVal := func() interface{} {
				val, err := strconv.ParseFloat(e.Target.Get("value").String(), 64)
				if err != nil {
					// if there's an error converting to a float, ignore it
					return nil
				}
				return val
			}
			val := getVal()
			changed := func() bool {
				return val != getVal()
			}
			go func() {
				<-time.After(common.EditorKeyboardDebounceShort)
				if changed() {
					return
				}
				v.App.Dispatch(&actions.Modify{
					Undoer:  &actions.Undoer{},
					Editor:  v.model,
					Before:  v.model.Node.NativeValue(),
					After:   val,
					Changed: changed,
				})
			}()
		}),
	)

	return elem.Div(v.input)
}