diff --git a/src/core/components/event_listener.h b/src/core/components/event_listener.h index b93e64d8ed1e5791c578205570280b8f63b43fb5..c8d78f67b2feaf910bfbb57e80a3a9b66bb8af38 100755 --- a/src/core/components/event_listener.h +++ b/src/core/components/event_listener.h @@ -37,6 +37,7 @@ public: componentId_ = componentId; isChanging_ = false; radio_ = nullptr; + value_ = nullptr; state_ = UICheckBox::UICheckBoxState::UNSELECTED; } @@ -62,6 +63,11 @@ public: ReleaseJerryValue(jerryx_set_property_str(args[0], name, nameVal), nameVal, VA_ARG_END_FLAG); } } + if (value_ != nullptr) { + const char * const valueName = "value"; + jerry_value_t valueProp = jerry_create_string(reinterpret_cast(value_)); + ReleaseJerryValue(jerryx_set_property_str(args[0], valueName, valueProp), valueProp, VA_ARG_END_FLAG); + } jerry_value_t globalObject = jerry_get_global_object(); jerry_value_t appViewModel = jerryx_get_property_str(globalObject, ATTR_APP); if (jerry_value_is_function(fn_)) { @@ -100,6 +106,10 @@ public: radio_ = radioButton; } + void SetValue(char* value) { + value_ = value; + } + ~StateChangeListener() { jerry_release_value(fn_); @@ -108,6 +118,7 @@ public: private: jerry_value_t fn_; uint16_t componentId_; + char* value_; UIRadioButton* radio_; UICheckBox::UICheckBoxState state_; bool isChanging_; // the flag to avoid change event cycle execute diff --git a/src/core/components/input_component.cpp b/src/core/components/input_component.cpp index 14f2f39539d866d30a5b881e6dbf0382f9304148..5749cc43a7f7479163541658beefc92c83a5e647 100755 --- a/src/core/components/input_component.cpp +++ b/src/core/components/input_component.cpp @@ -140,12 +140,9 @@ bool InputComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrV } break; case K_VALUE: - if (button_ != nullptr) { - ACE_FREE(textValue_); - textValue_ = MallocStringOf(attrValue); - return true; - } - break; + ACE_FREE(textValue_); + textValue_ = MallocStringOf(attrValue); + return true; case K_NAME: if (radioButton_ != nullptr) { char *name = MallocStringOf(attrValue); @@ -474,6 +471,7 @@ void InputComponent::DealEvent() return; } if (changeListener_ != nullptr) { + changeListener_->SetValue(textValue_); if (checkbox_ != nullptr) { checkbox_->SetOnChangeListener(changeListener_); } else { @@ -532,6 +530,10 @@ void InputComponent::PostUpdate(uint16_t attrKeyId, bool updateResult) break; } } + if (((checkbox_ != nullptr) || (radioButton_ != nullptr)) && (changeListener_ != nullptr) + && (attrKeyId == K_VALUE)) { + changeListener_->SetValue(textValue_); + } } } // namespace ACELite } // namespace OHOS