Fix labels and input types

This commit is contained in:
Frank A. Krueger 2017-06-24 14:52:34 -07:00
parent a780f97578
commit 779942ab62
4 changed files with 57 additions and 10 deletions

View File

@ -62,8 +62,10 @@ function msgSet (m) {
for (let i = 0; i < parts.length - 1; i++) { for (let i = 0; i < parts.length - 1; i++) {
o = o[parts[i]]; o = o[parts[i]];
} }
o[parts[parts.length - 1]] = m.v; const lastPart = parts[parts.length - 1];
if (debug) console.log ("Set", node, parts, m.v); const value = lastPart === "htmlFor" ? m.v.id : m.v;
o[lastPart] = value;
if (debug) console.log ("Set", node, parts, value);
} }
function msgCall (m) { function msgCall (m) {

View File

@ -1,4 +1,7 @@
using System; using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Ooui namespace Ooui
{ {
@ -77,37 +80,61 @@ namespace Ooui
protected override bool TriggerEventFromMessage (Message message) protected override bool TriggerEventFromMessage (Message message)
{ {
if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { 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
return true; val = message.Value != null ? Convert.ToString (message.Value) : "";
} }
return base.TriggerEventFromMessage (message); return base.TriggerEventFromMessage (message);
} }
} }
[JsonConverter (typeof (StringEnumConverter))]
public enum InputType public enum InputType
{ {
[EnumMember (Value = "text")]
Text, Text,
[EnumMember (Value = "date")]
Date, Date,
[EnumMember (Value = "week")]
Week, Week,
[EnumMember (Value = "datetime")]
Datetime, Datetime,
[EnumMember (Value = "datetimelocal")]
DatetimeLocal, DatetimeLocal,
[EnumMember (Value = "time")]
Time, Time,
[EnumMember (Value = "month")]
Month, Month,
[EnumMember (Value = "range")]
Range, Range,
[EnumMember (Value = "number")]
Number, Number,
[EnumMember (Value = "hidden")]
Hidden, Hidden,
[EnumMember (Value = "search")]
Search, Search,
[EnumMember (Value = "email")]
Email, Email,
[EnumMember (Value = "tel")]
Tel, Tel,
[EnumMember (Value = "url")]
Url, Url,
[EnumMember (Value = "password")]
Password, Password,
[EnumMember (Value = "color")]
Color, Color,
[EnumMember (Value = "checkbox")]
Checkbox, Checkbox,
[EnumMember (Value = "radio")]
Radio, Radio,
[EnumMember (Value = "file")]
File, File,
[EnumMember (Value = "submit")]
Submit, Submit,
[EnumMember (Value = "reset")]
Reset, Reset,
[EnumMember (Value = "image")]
Image, Image,
[EnumMember (Value = "button")]
Button, Button,
} }
} }

View File

@ -48,7 +48,8 @@ namespace Ooui
protected override bool TriggerEventFromMessage (Message message) protected override bool TriggerEventFromMessage (Message message)
{ {
if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { 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); return base.TriggerEventFromMessage (message);
} }

View File

@ -6,16 +6,33 @@ namespace Samples
{ {
public class TodoSample 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 () Element MakeTodo ()
{ {
var items = new List ();
var input = new Input (); var input = new Input ();
var button = new Button ("Add the item"); var button = new Button ("Add the item");
button.Clicked += (s, e) => { button.Clicked += (s, e) => {
items.AppendChild (new ListItem { if (string.IsNullOrWhiteSpace (input.Value))
Text = input.Value return;
}); var item = MakeItem (input.Value);
items.AppendChild (item);
input.Value = "";
}; };
var app = new Div (); var app = new Div ();
app.AppendChild (input); app.AppendChild (input);