From d08dd3a2bfc6e55936296e9a726247a2cfb615f0 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Fri, 23 Mar 2018 15:06:17 -0700 Subject: [PATCH] Fix Select and Option to use textContent instead of label This also fixes getting the initial value of the select. Fixes #103 --- Ooui/Select.cs | 36 +++++++++++++++++++++++------------- Samples/DrawSample.cs | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Ooui/Select.cs b/Ooui/Select.cs index 885de9b..e0b1b7e 100644 --- a/Ooui/Select.cs +++ b/Ooui/Select.cs @@ -1,12 +1,21 @@ using System; +using System.Linq; namespace Ooui { public class Select : FormControl { + bool gotValue = false; + public string Value { - get => GetStringAttribute ("value", ""); - set => SetAttributeProperty ("value", value ?? ""); + get { + if (gotValue) return GetStringAttribute ("value", ""); + return GetDefaultValue (); + } + set { + gotValue = true; + SetAttributeProperty ("value", value ?? ""); + } } public event TargetEventHandler Change { @@ -23,28 +32,29 @@ namespace Ooui : base ("select") { // Subscribe to the change event so we always get up-to-date values - Change += (s, e) => { }; + Change += (s, e) => { gotValue = true; }; } public void AddOption (string label, string value) { - AppendChild (new Option { Label = label, Value = value }); + AppendChild (new Option { Text = label, Value = value }); } - protected override void OnChildInsertedBefore (Node newChild, Node referenceChild) + string GetDefaultValue () { - base.OnChildInsertedBefore (newChild, referenceChild); - var val = Value; - if (string.IsNullOrEmpty (val) && newChild is Option o && !string.IsNullOrEmpty (o.Value)) { - val = o.Value; - } + var options = Children.OfType