From 779942ab628c7118c4dad715cb461e58eb697b75 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sat, 24 Jun 2017 14:52:34 -0700 Subject: [PATCH] Fix labels and input types --- Ooui/Client.js | 6 ++++-- Ooui/Input.cs | 31 +++++++++++++++++++++++++++++-- Ooui/TextArea.cs | 3 ++- Samples/TodoSample.cs | 27 ++++++++++++++++++++++----- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Ooui/Client.js b/Ooui/Client.js index 4be5c1b..0941fdb 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -62,8 +62,10 @@ function msgSet (m) { for (let i = 0; i < parts.length - 1; i++) { o = o[parts[i]]; } - o[parts[parts.length - 1]] = m.v; - if (debug) console.log ("Set", node, parts, m.v); + const lastPart = parts[parts.length - 1]; + const value = lastPart === "htmlFor" ? m.v.id : m.v; + o[lastPart] = value; + if (debug) console.log ("Set", node, parts, value); } function msgCall (m) { diff --git a/Ooui/Input.cs b/Ooui/Input.cs index 3bd9e1a..ba73324 100644 --- a/Ooui/Input.cs +++ b/Ooui/Input.cs @@ -1,4 +1,7 @@ using System; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Ooui { @@ -77,37 +80,61 @@ namespace Ooui protected override bool TriggerEventFromMessage (Message message) { if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { - Value = message.Value != null ? Convert.ToString (message.Value) : ""; - return true; + // Don't need to notify here because the base implementation will fire the event + val = message.Value != null ? Convert.ToString (message.Value) : ""; } return base.TriggerEventFromMessage (message); } } + [JsonConverter (typeof (StringEnumConverter))] public enum InputType { + [EnumMember (Value = "text")] Text, + [EnumMember (Value = "date")] Date, + [EnumMember (Value = "week")] Week, + [EnumMember (Value = "datetime")] Datetime, + [EnumMember (Value = "datetimelocal")] DatetimeLocal, + [EnumMember (Value = "time")] Time, + [EnumMember (Value = "month")] Month, + [EnumMember (Value = "range")] Range, + [EnumMember (Value = "number")] Number, + [EnumMember (Value = "hidden")] Hidden, + [EnumMember (Value = "search")] Search, + [EnumMember (Value = "email")] Email, + [EnumMember (Value = "tel")] Tel, + [EnumMember (Value = "url")] Url, + [EnumMember (Value = "password")] Password, + [EnumMember (Value = "color")] Color, + [EnumMember (Value = "checkbox")] Checkbox, + [EnumMember (Value = "radio")] Radio, + [EnumMember (Value = "file")] File, + [EnumMember (Value = "submit")] Submit, + [EnumMember (Value = "reset")] Reset, + [EnumMember (Value = "image")] Image, + [EnumMember (Value = "button")] Button, } } diff --git a/Ooui/TextArea.cs b/Ooui/TextArea.cs index 653bcef..b9a60f5 100644 --- a/Ooui/TextArea.cs +++ b/Ooui/TextArea.cs @@ -48,7 +48,8 @@ namespace Ooui protected override bool TriggerEventFromMessage (Message message) { if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { - Value = message.Value != null ? Convert.ToString (message.Value) : ""; + // Don't need to notify here because the base implementation will fire the event + val = message.Value != null ? Convert.ToString (message.Value) : ""; } return base.TriggerEventFromMessage (message); } diff --git a/Samples/TodoSample.cs b/Samples/TodoSample.cs index db5757a..4a926db 100644 --- a/Samples/TodoSample.cs +++ b/Samples/TodoSample.cs @@ -6,16 +6,33 @@ namespace Samples { public class TodoSample { + List items = new List (); + + Element MakeItem (string text) + { + 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; + } Element MakeTodo () - { - var items = new List (); + { var input = new Input (); var button = new Button ("Add the item"); button.Clicked += (s, e) => { - items.AppendChild (new ListItem { - Text = input.Value - }); + if (string.IsNullOrWhiteSpace (input.Value)) + return; + var item = MakeItem (input.Value); + items.AppendChild (item); + input.Value = ""; }; var app = new Div (); app.AppendChild (input);