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

View File

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