Просмотр исходного кода

Add "checked" property to checkbox and radio change event

This is helpful in cases where the checked state is used in boolean expressions.
Michael Ragazzon 1 месяц назад
Родитель
Сommit
dc5381ee69

+ 6 - 1
Source/Core/Elements/InputTypeCheckbox.cpp

@@ -52,7 +52,12 @@ bool InputTypeCheckbox::OnAttributeChange(const ElementAttributes& changed_attri
 	{
 		const bool checked = element->HasAttribute("checked");
 		element->SetPseudoClass("checked", checked);
-		element->DispatchEvent(EventId::Change, {{"data-binding-override-value", Variant(checked)}, {"value", Variant(checked ? GetValue() : "")}});
+		element->DispatchEvent(EventId::Change,
+			{
+				{"data-binding-override-value", Variant(checked)},
+				{"value", Variant(checked ? GetValue() : "")},
+				{"checked", Variant(checked)},
+			});
 	}
 
 	return true;

+ 7 - 3
Source/Core/Elements/InputTypeRadio.cpp

@@ -57,7 +57,7 @@ bool InputTypeRadio::OnAttributeChange(const ElementAttributes& changed_attribut
 {
 	if (changed_attributes.count("checked"))
 	{
-		bool checked = element->HasAttribute("checked");
+		const bool checked = element->HasAttribute("checked");
 		element->SetPseudoClass("checked", checked);
 
 		if (checked)
@@ -65,7 +65,11 @@ bool InputTypeRadio::OnAttributeChange(const ElementAttributes& changed_attribut
 
 		const auto perceived_value = Variant(checked ? GetValue() : "");
 		element->DispatchEvent(EventId::Change,
-			{{"data-binding-override-value", checked ? Variant(perceived_value) : Variant()}, {"value", perceived_value}});
+			{
+				{"data-binding-override-value", checked ? perceived_value : Variant()},
+				{"value", perceived_value},
+				{"checked", Variant(checked)},
+			});
 	}
 
 	return true;
@@ -100,7 +104,7 @@ void InputTypeRadio::PopRadioSet()
 	while (parent != nullptr && rmlui_dynamic_cast<ElementForm*>(parent) == nullptr)
 		parent = parent->GetParentNode();
 
-	//If no containing form was found, use the containing document as the parent
+	// If no containing form was found, use the containing document as the parent
 	if (parent == nullptr)
 	{
 		parent = element->GetOwnerDocument();