Fix getting checkbox values

This commit is contained in:
Frank A. Krueger 2017-06-24 15:21:48 -07:00
parent 779942ab62
commit fff50cce00
3 changed files with 27 additions and 15 deletions

View File

@ -97,7 +97,9 @@ function msgListen (m) {
k: m.k, k: m.k,
}; };
if (m.k === "change" || m.k === "input") { 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); const ems = JSON.stringify (em);
socket.send (ems); socket.send (ems);

View File

@ -81,7 +81,12 @@ namespace Ooui
{ {
if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { 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 // 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); return base.TriggerEventFromMessage (message);
} }

View File

@ -8,19 +8,24 @@ namespace Samples
{ {
List items = new List (); List items = new List ();
Element MakeItem (string text) class Item : ListItem
{ {
var li = new ListItem (); public Item (string text)
var check = new Input { {
Type = InputType.Checkbox, var check = new Input {
}; Type = InputType.Checkbox,
var label = new Label { };
Text = text, var label = new Label {
For = check Text = text,
}; For = check
li.AppendChild (check); };
li.AppendChild (label); check.Changed += (s,e) => {
return li; label.Style.TextDecoration =
check.IsChecked ? "line-through" : "none";
};
AppendChild (check);
AppendChild (label);
}
} }
Element MakeTodo () Element MakeTodo ()
@ -30,7 +35,7 @@ namespace Samples
button.Clicked += (s, e) => { button.Clicked += (s, e) => {
if (string.IsNullOrWhiteSpace (input.Value)) if (string.IsNullOrWhiteSpace (input.Value))
return; return;
var item = MakeItem (input.Value); var item = new Item (input.Value);
items.AppendChild (item); items.AppendChild (item);
input.Value = ""; input.Value = "";
}; };