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,8 +81,13 @@ 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
if (Type == InputType.Checkbox) {
isChecked = message.Value != null ? Convert.ToBoolean (message.Value) : false;
}
else {
val = message.Value != null ? Convert.ToString (message.Value) : ""; val = message.Value != null ? Convert.ToString (message.Value) : "";
} }
}
return base.TriggerEventFromMessage (message); return base.TriggerEventFromMessage (message);
} }
} }

View File

@ -8,9 +8,10 @@ namespace Samples
{ {
List items = new List (); List items = new List ();
Element MakeItem (string text) class Item : ListItem
{
public Item (string text)
{ {
var li = new ListItem ();
var check = new Input { var check = new Input {
Type = InputType.Checkbox, Type = InputType.Checkbox,
}; };
@ -18,9 +19,13 @@ namespace Samples
Text = text, Text = text,
For = check For = check
}; };
li.AppendChild (check); check.Changed += (s,e) => {
li.AppendChild (label); label.Style.TextDecoration =
return li; 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 = "";
}; };