2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// EditTextChangedEvent is the constant for the "edit-text-changed" property tag.
|
|
|
|
EditTextChangedEvent = "edit-text-changed"
|
2024-05-18 18:57:41 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// EditViewType is the constant for the "edit-view-type" property tag.
|
|
|
|
EditViewType = "edit-view-type"
|
2024-05-18 18:57:41 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// EditViewPattern is the constant for the "edit-view-pattern" property tag.
|
|
|
|
EditViewPattern = "edit-view-pattern"
|
2024-05-18 18:57:41 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
// Spellcheck is the constant for the "spellcheck" property tag.
|
|
|
|
Spellcheck = "spellcheck"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// SingleLineText - single-line text type of EditView
|
|
|
|
SingleLineText = 0
|
|
|
|
// PasswordText - password type of EditView
|
|
|
|
PasswordText = 1
|
|
|
|
// EmailText - e-mail type of EditView. Allows to enter one email
|
|
|
|
EmailText = 2
|
2022-11-23 15:10:29 +03:00
|
|
|
// EmailsText - e-mail type of EditView. Allows to enter multiple emails separated by comma
|
2021-09-07 17:36:50 +03:00
|
|
|
EmailsText = 3
|
|
|
|
// URLText - url type of EditView. Allows to enter one url
|
|
|
|
URLText = 4
|
|
|
|
// PhoneText - telephone type of EditView. Allows to enter one phone number
|
|
|
|
PhoneText = 5
|
|
|
|
// MultiLineText - multi-line text type of EditView
|
|
|
|
MultiLineText = 6
|
|
|
|
)
|
|
|
|
|
|
|
|
// EditView - grid-container of View
|
|
|
|
type EditView interface {
|
|
|
|
View
|
|
|
|
AppendText(text string)
|
|
|
|
}
|
|
|
|
|
|
|
|
type editViewData struct {
|
|
|
|
viewData
|
2024-05-18 18:57:41 +03:00
|
|
|
dataList
|
2023-04-23 18:07:01 +03:00
|
|
|
textChangeListeners []func(EditView, string, string)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewEditView create new EditView object and return it
|
|
|
|
func NewEditView(session Session, params Params) EditView {
|
|
|
|
view := new(editViewData)
|
2022-09-01 11:04:50 +03:00
|
|
|
view.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
setInitParams(view, params)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
func newEditView(session Session) View {
|
|
|
|
return NewEditView(session, nil)
|
|
|
|
}
|
|
|
|
|
2022-09-01 11:04:50 +03:00
|
|
|
func (edit *editViewData) init(session Session) {
|
|
|
|
edit.viewData.init(session)
|
2024-04-23 18:24:51 +03:00
|
|
|
edit.hasHtmlDisabled = true
|
2023-04-23 18:07:01 +03:00
|
|
|
edit.textChangeListeners = []func(EditView, string, string){}
|
2021-09-07 17:36:50 +03:00
|
|
|
edit.tag = "EditView"
|
2024-05-18 18:57:41 +03:00
|
|
|
edit.dataListInit()
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2022-05-22 12:54:02 +03:00
|
|
|
func (edit *editViewData) String() string {
|
2024-05-02 15:07:57 +03:00
|
|
|
return getViewString(edit, nil)
|
2022-05-22 12:54:02 +03:00
|
|
|
}
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
func (edit *editViewData) Focusable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
func (edit *editViewData) normalizeTag(tag string) string {
|
|
|
|
tag = strings.ToLower(tag)
|
|
|
|
switch tag {
|
|
|
|
case Type, "edit-type":
|
|
|
|
return EditViewType
|
|
|
|
|
|
|
|
case Pattern, "edit-pattern":
|
|
|
|
return EditViewPattern
|
|
|
|
|
|
|
|
case "maxlength", "maxlen":
|
|
|
|
return MaxLength
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
|
|
|
|
case "wrap":
|
|
|
|
return EditWrap
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-05-18 18:57:41 +03:00
|
|
|
return edit.normalizeDataListTag(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (edit *editViewData) Remove(tag string) {
|
|
|
|
edit.remove(edit.normalizeTag(tag))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (edit *editViewData) remove(tag string) {
|
2021-11-20 11:15:28 +03:00
|
|
|
_, exists := edit.properties[tag]
|
|
|
|
switch tag {
|
|
|
|
case Hint:
|
|
|
|
if exists {
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, Hint)
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), "placeholder")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
|
|
|
edit.propertyChangedEvent(tag)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
case MaxLength:
|
|
|
|
if exists {
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, MaxLength)
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), "maxlength")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
|
|
|
edit.propertyChangedEvent(tag)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
case ReadOnly, Spellcheck:
|
|
|
|
if exists {
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, tag)
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-10-31 16:07:59 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), tag, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
case EditTextChangedEvent:
|
|
|
|
if len(edit.textChangeListeners) > 0 {
|
2023-04-23 18:07:01 +03:00
|
|
|
edit.textChangeListeners = []func(EditView, string, string){}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
case Text:
|
|
|
|
if exists {
|
2022-08-31 22:17:46 +03:00
|
|
|
oldText := GetText(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, tag)
|
|
|
|
if oldText != "" {
|
2023-04-23 18:07:01 +03:00
|
|
|
edit.textChanged("", oldText)
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-11-02 20:10:19 +03:00
|
|
|
edit.session.callFunc("setInputValue", edit.htmlID(), "")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
case EditViewPattern:
|
|
|
|
if exists {
|
2022-08-31 22:17:46 +03:00
|
|
|
oldText := GetEditViewPattern(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, tag)
|
|
|
|
if oldText != "" {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), Pattern)
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
case EditViewType:
|
|
|
|
if exists {
|
2022-08-31 22:17:46 +03:00
|
|
|
oldType := GetEditViewType(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, tag)
|
|
|
|
if oldType != 0 {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
updateInnerHTML(edit.parentHTMLID(), edit.session)
|
|
|
|
}
|
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
case EditWrap:
|
2021-11-20 11:15:28 +03:00
|
|
|
if exists {
|
2022-08-31 22:17:46 +03:00
|
|
|
oldWrap := IsEditViewWrap(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(edit.properties, tag)
|
2022-08-31 22:17:46 +03:00
|
|
|
if GetEditViewType(edit) == MultiLineText {
|
|
|
|
if wrap := IsEditViewWrap(edit); wrap != oldWrap {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
if wrap {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), "wrap", "soft")
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), "wrap", "off")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
|
2024-05-18 18:57:41 +03:00
|
|
|
case DataList:
|
|
|
|
if len(edit.dataList.dataList) > 0 {
|
|
|
|
edit.setDataList(edit, []string{}, true)
|
|
|
|
}
|
|
|
|
|
2021-11-20 11:15:28 +03:00
|
|
|
default:
|
|
|
|
edit.viewData.remove(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (edit *editViewData) Set(tag string, value any) bool {
|
2021-09-07 17:36:50 +03:00
|
|
|
return edit.set(edit.normalizeTag(tag), value)
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (edit *editViewData) set(tag string, value any) bool {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value == nil {
|
|
|
|
edit.remove(tag)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
switch tag {
|
|
|
|
case Text:
|
|
|
|
if text, ok := value.(string); ok {
|
2024-05-29 15:31:58 +03:00
|
|
|
oldText := GetText(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
edit.properties[Text] = text
|
2022-08-31 22:17:46 +03:00
|
|
|
if text = GetText(edit); oldText != text {
|
2023-04-23 18:07:01 +03:00
|
|
|
edit.textChanged(text, oldText)
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2024-05-16 11:13:45 +03:00
|
|
|
edit.session.callFunc("setInputValue", edit.htmlID(), text)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
case Hint:
|
|
|
|
if text, ok := value.(string); ok {
|
2024-05-29 15:31:58 +03:00
|
|
|
oldText := GetHint(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
edit.properties[Hint] = text
|
2022-08-31 22:17:46 +03:00
|
|
|
if text = GetHint(edit); oldText != text {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
if text != "" {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), "placeholder", text)
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), "placeholder")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
case MaxLength:
|
2022-08-31 22:17:46 +03:00
|
|
|
oldMaxLength := GetMaxLength(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
if edit.setIntProperty(MaxLength, value) {
|
2022-08-31 22:17:46 +03:00
|
|
|
if maxLength := GetMaxLength(edit); maxLength != oldMaxLength {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
if maxLength > 0 {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), "maxlength", strconv.Itoa(maxLength))
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), "maxlength")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
case ReadOnly:
|
|
|
|
if edit.setBoolProperty(ReadOnly, value) {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-08-31 22:17:46 +03:00
|
|
|
if IsReadOnly(edit) {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), ReadOnly, "")
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), ReadOnly)
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
case Spellcheck:
|
|
|
|
if edit.setBoolProperty(Spellcheck, value) {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
2022-10-31 16:07:59 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), Spellcheck, IsSpellcheck(edit))
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
case EditViewPattern:
|
2022-08-31 22:17:46 +03:00
|
|
|
oldText := GetEditViewPattern(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
if text, ok := value.(string); ok {
|
2022-05-16 17:43:06 +03:00
|
|
|
edit.properties[EditViewPattern] = text
|
2022-08-31 22:17:46 +03:00
|
|
|
if text = GetEditViewPattern(edit); oldText != text {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
if text != "" {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), Pattern, text)
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.removeProperty(edit.htmlID(), Pattern)
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
case EditViewType:
|
2022-08-31 22:17:46 +03:00
|
|
|
oldType := GetEditViewType(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
if edit.setEnumProperty(EditViewType, value, enumProperties[EditViewType].values) {
|
2022-08-31 22:17:46 +03:00
|
|
|
if GetEditViewType(edit) != oldType {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
updateInnerHTML(edit.parentHTMLID(), edit.session)
|
|
|
|
}
|
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
case EditWrap:
|
2022-08-31 22:17:46 +03:00
|
|
|
oldWrap := IsEditViewWrap(edit)
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
if edit.setBoolProperty(EditWrap, value) {
|
2022-08-31 22:17:46 +03:00
|
|
|
if GetEditViewType(edit) == MultiLineText {
|
|
|
|
if wrap := IsEditViewWrap(edit); wrap != oldWrap {
|
2021-11-20 11:15:28 +03:00
|
|
|
if edit.created {
|
|
|
|
if wrap {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), "wrap", "soft")
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2022-10-30 17:22:33 +03:00
|
|
|
edit.session.updateProperty(edit.htmlID(), "wrap", "off")
|
2021-11-20 11:15:28 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
2024-05-18 18:57:41 +03:00
|
|
|
case DataList:
|
|
|
|
return edit.setDataList(edit, value, edit.created)
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
case EditTextChangedEvent:
|
2023-04-23 18:07:01 +03:00
|
|
|
listeners, ok := valueToEventWithOldListeners[EditView, string](value)
|
2021-09-07 17:36:50 +03:00
|
|
|
if !ok {
|
|
|
|
notCompatibleType(tag, value)
|
2022-07-27 20:31:57 +03:00
|
|
|
return false
|
|
|
|
} else if listeners == nil {
|
2023-04-23 18:07:01 +03:00
|
|
|
listeners = []func(EditView, string, string){}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2022-07-27 20:31:57 +03:00
|
|
|
edit.textChangeListeners = listeners
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(tag)
|
2022-07-27 20:31:57 +03:00
|
|
|
return true
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return edit.viewData.set(tag, value)
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (edit *editViewData) Get(tag string) any {
|
2021-09-07 17:36:50 +03:00
|
|
|
return edit.get(edit.normalizeTag(tag))
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:36:00 +03:00
|
|
|
func (edit *editViewData) get(tag string) any {
|
2024-05-18 18:57:41 +03:00
|
|
|
switch tag {
|
|
|
|
case EditTextChangedEvent:
|
2022-07-27 20:31:57 +03:00
|
|
|
return edit.textChangeListeners
|
2024-05-18 18:57:41 +03:00
|
|
|
|
|
|
|
case DataList:
|
|
|
|
return edit.dataList.dataList
|
2022-07-27 20:31:57 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
return edit.viewData.get(tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (edit *editViewData) AppendText(text string) {
|
2022-08-31 22:17:46 +03:00
|
|
|
if GetEditViewType(edit) == MultiLineText {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value := edit.getRaw(Text); value != nil {
|
|
|
|
if textValue, ok := value.(string); ok {
|
2023-04-23 18:07:01 +03:00
|
|
|
oldText := textValue
|
2021-09-07 17:36:50 +03:00
|
|
|
textValue += text
|
|
|
|
edit.properties[Text] = textValue
|
2022-11-02 20:10:19 +03:00
|
|
|
edit.session.callFunc("appendToInnerHTML", edit.htmlID(), text)
|
2023-04-23 18:07:01 +03:00
|
|
|
edit.textChanged(textValue, oldText)
|
2021-09-07 17:36:50 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
edit.set(Text, text)
|
|
|
|
} else {
|
2022-08-31 22:17:46 +03:00
|
|
|
edit.set(Text, GetText(edit)+text)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-23 18:07:01 +03:00
|
|
|
func (edit *editViewData) textChanged(newText, oldText string) {
|
2021-09-07 17:36:50 +03:00
|
|
|
for _, listener := range edit.textChangeListeners {
|
2023-04-23 18:07:01 +03:00
|
|
|
listener(edit, newText, oldText)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2021-11-20 11:15:28 +03:00
|
|
|
edit.propertyChangedEvent(Text)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (edit *editViewData) htmlTag() string {
|
2022-08-31 22:17:46 +03:00
|
|
|
if GetEditViewType(edit) == MultiLineText {
|
2021-09-07 17:36:50 +03:00
|
|
|
return "textarea"
|
|
|
|
}
|
|
|
|
return "input"
|
|
|
|
}
|
|
|
|
|
2024-05-18 18:57:41 +03:00
|
|
|
func (edit *editViewData) htmlSubviews(self View, buffer *strings.Builder) {
|
2024-05-29 15:31:58 +03:00
|
|
|
if GetEditViewType(edit) == MultiLineText {
|
|
|
|
if text := GetText(edit); text != "" {
|
|
|
|
buffer.WriteString(text)
|
|
|
|
}
|
|
|
|
}
|
2024-05-18 18:57:41 +03:00
|
|
|
edit.dataListHtmlSubviews(self, buffer)
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
func (edit *editViewData) htmlProperties(self View, buffer *strings.Builder) {
|
|
|
|
edit.viewData.htmlProperties(self, buffer)
|
|
|
|
|
|
|
|
writeSpellcheck := func() {
|
2022-08-31 22:17:46 +03:00
|
|
|
if spellcheck := IsSpellcheck(edit); spellcheck {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` spellcheck="true"`)
|
|
|
|
} else {
|
|
|
|
buffer.WriteString(` spellcheck="false"`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 22:17:46 +03:00
|
|
|
editType := GetEditViewType(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
switch editType {
|
|
|
|
case SingleLineText:
|
|
|
|
buffer.WriteString(` type="text" inputmode="text"`)
|
|
|
|
writeSpellcheck()
|
|
|
|
|
|
|
|
case PasswordText:
|
|
|
|
buffer.WriteString(` type="password" inputmode="text"`)
|
|
|
|
|
|
|
|
case EmailText:
|
|
|
|
buffer.WriteString(` type="email" inputmode="email"`)
|
|
|
|
|
|
|
|
case EmailsText:
|
|
|
|
buffer.WriteString(` type="email" inputmode="email" multiple`)
|
|
|
|
|
|
|
|
case URLText:
|
|
|
|
buffer.WriteString(` type="url" inputmode="url"`)
|
|
|
|
|
|
|
|
case PhoneText:
|
|
|
|
buffer.WriteString(` type="tel" inputmode="tel"`)
|
|
|
|
|
|
|
|
case MultiLineText:
|
2022-08-31 22:17:46 +03:00
|
|
|
if IsEditViewWrap(edit) {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` wrap="soft"`)
|
|
|
|
} else {
|
|
|
|
buffer.WriteString(` wrap="off"`)
|
|
|
|
}
|
|
|
|
writeSpellcheck()
|
|
|
|
}
|
|
|
|
|
2022-08-31 22:17:46 +03:00
|
|
|
if IsReadOnly(edit) {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` readonly`)
|
|
|
|
}
|
|
|
|
|
2022-08-31 22:17:46 +03:00
|
|
|
if maxLength := GetMaxLength(edit); maxLength > 0 {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` maxlength="`)
|
|
|
|
buffer.WriteString(strconv.Itoa(maxLength))
|
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
|
|
|
|
2022-05-26 12:01:49 +03:00
|
|
|
convertText := func(text string) string {
|
|
|
|
if strings.ContainsRune(text, '"') {
|
|
|
|
text = strings.ReplaceAll(text, `"`, `"`)
|
|
|
|
}
|
2024-05-16 11:13:45 +03:00
|
|
|
if strings.ContainsRune(text, '\n') {
|
|
|
|
text = strings.ReplaceAll(text, "\n", `\n`)
|
|
|
|
}
|
2022-10-29 21:08:51 +03:00
|
|
|
return text
|
2022-05-26 12:01:49 +03:00
|
|
|
}
|
|
|
|
|
2022-08-31 22:17:46 +03:00
|
|
|
if hint := GetHint(edit); hint != "" {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` placeholder="`)
|
2022-05-26 12:01:49 +03:00
|
|
|
buffer.WriteString(convertText(hint))
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.WriteString(` oninput="editViewInputEvent(this)"`)
|
2022-08-31 22:17:46 +03:00
|
|
|
if pattern := GetEditViewPattern(edit); pattern != "" {
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteString(` pattern="`)
|
2022-05-26 12:01:49 +03:00
|
|
|
buffer.WriteString(convertText(pattern))
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:31:58 +03:00
|
|
|
if editType != MultiLineText {
|
|
|
|
if text := GetText(edit); text != "" {
|
|
|
|
buffer.WriteString(` value="`)
|
|
|
|
buffer.WriteString(convertText(text))
|
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2024-05-18 18:57:41 +03:00
|
|
|
|
2024-05-29 15:31:58 +03:00
|
|
|
edit.dataListHtmlProperties(edit, buffer)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (edit *editViewData) handleCommand(self View, command string, data DataObject) bool {
|
|
|
|
switch command {
|
|
|
|
case "textChanged":
|
2022-08-31 22:17:46 +03:00
|
|
|
oldText := GetText(edit)
|
2021-09-07 17:36:50 +03:00
|
|
|
if text, ok := data.PropertyValue("text"); ok {
|
|
|
|
edit.properties[Text] = text
|
2022-08-31 22:17:46 +03:00
|
|
|
if text := GetText(edit); text != oldText {
|
2023-04-23 18:07:01 +03:00
|
|
|
edit.textChanged(text, oldText)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return edit.viewData.handleCommand(self, command, data)
|
|
|
|
}
|
|
|
|
|
2022-05-17 10:46:00 +03:00
|
|
|
// GetText returns a text of the EditView subview.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a text of the first argument (view) is returned.
|
|
|
|
func GetText(view View, subviewID ...string) string {
|
|
|
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
|
|
|
view = ViewByID(view, subviewID[0])
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
if view != nil {
|
2021-11-17 12:47:14 +03:00
|
|
|
if value := view.getRaw(Text); value != nil {
|
|
|
|
if text, ok := value.(string); ok {
|
|
|
|
return text
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHint returns a hint text of the subview.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a text of the first argument (view) is returned.
|
|
|
|
func GetHint(view View, subviewID ...string) string {
|
|
|
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
|
|
|
view = ViewByID(view, subviewID[0])
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2024-04-22 16:35:18 +03:00
|
|
|
|
|
|
|
session := view.Session()
|
|
|
|
text := ""
|
2021-09-07 17:36:50 +03:00
|
|
|
if view != nil {
|
2024-04-22 16:35:18 +03:00
|
|
|
var ok bool
|
|
|
|
text, ok = stringProperty(view, Hint, view.Session())
|
|
|
|
if !ok {
|
|
|
|
if value := valueFromStyle(view, Hint); value != nil {
|
|
|
|
if text, ok = value.(string); ok {
|
|
|
|
if text, ok = session.resolveConstants(text); !ok {
|
|
|
|
text = ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
text = ""
|
2022-05-23 15:22:14 +03:00
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-22 16:35:18 +03:00
|
|
|
|
|
|
|
if text != "" && !GetNotTranslate(view) {
|
|
|
|
text, _ = session.GetString(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
return text
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2022-11-23 15:10:29 +03:00
|
|
|
// GetMaxLength returns a maximal length of EditView. If a maximal length is not limited then 0 is returned
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value of the first argument (view) is returned.
|
|
|
|
func GetMaxLength(view View, subviewID ...string) int {
|
2022-07-28 12:11:27 +03:00
|
|
|
return intStyledProperty(view, subviewID, MaxLength, 0)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsReadOnly returns the true if a EditView works in read only mode.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value of the first argument (view) is returned.
|
|
|
|
func IsReadOnly(view View, subviewID ...string) bool {
|
2022-07-28 12:11:27 +03:00
|
|
|
return boolStyledProperty(view, subviewID, ReadOnly, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsSpellcheck returns a value of the Spellcheck property of EditView.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func IsSpellcheck(view View, subviewID ...string) bool {
|
2022-07-28 12:11:27 +03:00
|
|
|
return boolStyledProperty(view, subviewID, Spellcheck, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTextChangedListeners returns the TextChangedListener list of an EditView or MultiLineEditView subview.
|
|
|
|
// If there are no listeners then the empty list is returned
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
2023-04-23 18:07:01 +03:00
|
|
|
func GetTextChangedListeners(view View, subviewID ...string) []func(EditView, string, string) {
|
|
|
|
return getEventWithOldListeners[EditView, string](view, subviewID, EditTextChangedEvent)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetEditViewType returns a value of the Type property of EditView.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetEditViewType(view View, subviewID ...string) int {
|
2022-07-28 12:41:50 +03:00
|
|
|
return enumStyledProperty(view, subviewID, EditViewType, SingleLineText, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetEditViewPattern returns a value of the Pattern property of EditView.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetEditViewPattern(view View, subviewID ...string) string {
|
|
|
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
|
|
|
view = ViewByID(view, subviewID[0])
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
if view != nil {
|
|
|
|
if pattern, ok := stringProperty(view, EditViewPattern, view.Session()); ok {
|
|
|
|
return pattern
|
|
|
|
}
|
2022-05-23 15:22:14 +03:00
|
|
|
if value := valueFromStyle(view, EditViewPattern); value != nil {
|
|
|
|
if pattern, ok := value.(string); ok {
|
|
|
|
if pattern, ok = view.Session().resolveConstants(pattern); ok {
|
|
|
|
return pattern
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// IsEditViewWrap returns a value of the EditWrap property of MultiLineEditView.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func IsEditViewWrap(view View, subviewID ...string) bool {
|
2022-07-28 12:11:27 +03:00
|
|
|
return boolStyledProperty(view, subviewID, EditWrap, false)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// AppendEditText appends the text to the EditView content.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
2021-09-07 17:36:50 +03:00
|
|
|
func AppendEditText(view View, subviewID string, text string) {
|
|
|
|
if subviewID != "" {
|
|
|
|
if edit := EditViewByID(view, subviewID); edit != nil {
|
|
|
|
edit.AppendText(text)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if edit, ok := view.(EditView); ok {
|
|
|
|
edit.AppendText(text)
|
|
|
|
}
|
|
|
|
}
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
|
2022-11-23 15:10:29 +03:00
|
|
|
// GetCaretColor returns the color of the text input caret.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetCaretColor(view View, subviewID ...string) Color {
|
2022-07-28 12:11:27 +03:00
|
|
|
return colorStyledProperty(view, subviewID, CaretColor, false)
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
}
|