forked from mbk-lab/rui_orig
2
0
Fork 0

Changed the main DatePicker listener

This commit is contained in:
anoshenko 2023-04-23 18:47:07 +03:00
parent 05fa725003
commit 4e7dd37f6a
3 changed files with 39 additions and 22 deletions

View File

@ -3184,9 +3184,9 @@ NumberChangedEvent). Основной слушатель события име
Дополнительные слушатели события могут иметь следующий формат
func(picker NumberPicker, newValue string)
func(newValue, oldValue string)
func(newValue string)
func(picker NumberPicker, newValue float64)
func(newValue, oldValue float64)
func(newValue float64)
func(picker NumberPicker)
func()
@ -3232,13 +3232,21 @@ NumberChangedEvent). Основной слушатель события име
Для отслеживания изменения вводимого значения используется событие "date-changed" (константа
DateChangedEvent). Основной слушатель события имеет следующий формат:
func(picker DatePicker, newDate time.Time)
func(picker DatePicker, newDate, oldDate time.Time)
где второй аргумент это новое значение даты
где второй аргумент это новое значение даты, третий аргумент - предыдущее значение даты.
Дополнительные слушатели события могут иметь следующий формат
func(picker DatePicker, newDate time.Time)
func(newDate, oldDate time.Time)
func(newDate time.Time)
func(picker DatePicker)
func()
Получить текущий список слушателей изменения даты можно с помощью функции
func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time)
func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time, time.Time)
## TimePicker

View File

@ -3147,9 +3147,9 @@ where the second argument is the new value, the third argument is the previous v
Additional event listeners can have the following format
func(picker NumberPicker, newValue string)
func(newValue, oldValue string)
func(newValue string)
func(picker NumberPicker, newValue float64)
func(newValue, oldValue float64)
func(newValue float64)
func(picker NumberPicker)
func()
@ -3196,13 +3196,21 @@ You can read the values of these properties using the functions:
The "date-changed" event (DateChangedEvent constant) is used to track the change in the entered value.
The main event listener has the following format:
func(picker DatePicker, newDate time.Time)
func(picker DatePicker, newDate, oldDate time.Time)
where the second argument is the new date value
where the second argument is the new date value, the third argument is the previous date value.
Additional event listeners can have the following format
func(picker DatePicker, newDate time.Time)
func(newDate, oldDate time.Time)
func(newDate time.Time)
func(picker DatePicker)
func()
You can get the current list of date change listeners using the function
func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time)
func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time, time.Time)
## TimePicker

View File

@ -22,7 +22,7 @@ type DatePicker interface {
type datePickerData struct {
viewData
dateChangedListeners []func(DatePicker, time.Time)
dateChangedListeners []func(DatePicker, time.Time, time.Time)
}
// NewDatePicker create new DatePicker object and return it
@ -40,7 +40,7 @@ func newDatePicker(session Session) View {
func (picker *datePickerData) init(session Session) {
picker.viewData.init(session)
picker.tag = "DatePicker"
picker.dateChangedListeners = []func(DatePicker, time.Time){}
picker.dateChangedListeners = []func(DatePicker, time.Time, time.Time){}
}
func (picker *datePickerData) String() string {
@ -69,7 +69,7 @@ func (picker *datePickerData) remove(tag string) {
switch tag {
case DateChangedEvent:
if len(picker.dateChangedListeners) > 0 {
picker.dateChangedListeners = []func(DatePicker, time.Time){}
picker.dateChangedListeners = []func(DatePicker, time.Time, time.Time){}
picker.propertyChangedEvent(tag)
}
return
@ -94,13 +94,14 @@ func (picker *datePickerData) remove(tag string) {
case DatePickerValue:
if _, ok := picker.properties[DatePickerValue]; ok {
oldDate := GetDatePickerValue(picker)
delete(picker.properties, DatePickerValue)
date := GetDatePickerValue(picker)
if picker.created {
picker.session.callFunc("setInputValue", picker.htmlID(), date.Format(dateFormat))
}
for _, listener := range picker.dateChangedListeners {
listener(picker, date)
listener(picker, date, oldDate)
}
} else {
return
@ -226,7 +227,7 @@ func (picker *datePickerData) set(tag string, value any) bool {
picker.session.callFunc("setInputValue", picker.htmlID(), date.Format(dateFormat))
}
for _, listener := range picker.dateChangedListeners {
listener(picker, date)
listener(picker, date, oldDate)
}
picker.propertyChangedEvent(tag)
}
@ -234,12 +235,12 @@ func (picker *datePickerData) set(tag string, value any) bool {
}
case DateChangedEvent:
listeners, ok := valueToEventListeners[DatePicker, time.Time](value)
listeners, ok := valueToEventWithOldListeners[DatePicker, time.Time](value)
if !ok {
notCompatibleType(tag, value)
return false
} else if listeners == nil {
listeners = []func(DatePicker, time.Time){}
listeners = []func(DatePicker, time.Time, time.Time){}
}
picker.dateChangedListeners = listeners
picker.propertyChangedEvent(tag)
@ -318,7 +319,7 @@ func (picker *datePickerData) handleCommand(self View, command string, data Data
picker.properties[DatePickerValue] = value
if value != oldValue {
for _, listener := range picker.dateChangedListeners {
listener(picker, value)
listener(picker, value, oldValue)
}
}
}
@ -410,6 +411,6 @@ func GetDatePickerValue(view View, subviewID ...string) time.Time {
// GetDateChangedListeners returns the DateChangedListener list of an DatePicker subview.
// If there are no listeners then the empty list is returned
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time) {
return getEventListeners[DatePicker, time.Time](view, subviewID, DateChangedEvent)
func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time, time.Time) {
return getEventWithOldListeners[DatePicker, time.Time](view, subviewID, DateChangedEvent)
}