diff --git a/Ooui/Client.js b/Ooui/Client.js index 0941fdb..4216db8 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -97,7 +97,9 @@ function msgListen (m) { k: m.k, }; if (m.k === "change" || m.k === "input") { - em.v = node.value; + em.v = (node.tagName === "INPUT" && node.type === "checkbox") ? + node.checked : + node.value; } const ems = JSON.stringify (em); socket.send (ems); diff --git a/Ooui/Input.cs b/Ooui/Input.cs index ba73324..b6bab86 100644 --- a/Ooui/Input.cs +++ b/Ooui/Input.cs @@ -81,7 +81,12 @@ namespace Ooui { if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { // Don't need to notify here because the base implementation will fire the event - val = message.Value != null ? Convert.ToString (message.Value) : ""; + if (Type == InputType.Checkbox) { + isChecked = message.Value != null ? Convert.ToBoolean (message.Value) : false; + } + else { + val = message.Value != null ? Convert.ToString (message.Value) : ""; + } } return base.TriggerEventFromMessage (message); } diff --git a/Samples/TodoSample.cs b/Samples/TodoSample.cs index 4a926db..ff7bf6c 100644 --- a/Samples/TodoSample.cs +++ b/Samples/TodoSample.cs @@ -8,19 +8,24 @@ namespace Samples { List items = new List (); - Element MakeItem (string text) + class Item : ListItem { - var li = new ListItem (); - var check = new Input { - Type = InputType.Checkbox, - }; - var label = new Label { - Text = text, - For = check - }; - li.AppendChild (check); - li.AppendChild (label); - return li; + public Item (string text) + { + var check = new Input { + Type = InputType.Checkbox, + }; + var label = new Label { + Text = text, + For = check + }; + check.Changed += (s,e) => { + label.Style.TextDecoration = + check.IsChecked ? "line-through" : "none"; + }; + AppendChild (check); + AppendChild (label); + } } Element MakeTodo () @@ -30,7 +35,7 @@ namespace Samples button.Clicked += (s, e) => { if (string.IsNullOrWhiteSpace (input.Value)) return; - var item = MakeItem (input.Value); + var item = new Item (input.Value); items.AppendChild (item); input.Value = ""; };