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,
};
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);

View File

@ -81,8 +81,13 @@ 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
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);
}
}

View File

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