2017-06-16 06:41:38 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ooui
|
|
|
|
{
|
|
|
|
public class Select : FormControl
|
|
|
|
{
|
|
|
|
string val = "";
|
|
|
|
public string Value {
|
|
|
|
get => val;
|
|
|
|
set => SetProperty (ref val, value ?? "", "value");
|
|
|
|
}
|
|
|
|
|
2017-12-10 23:07:33 +00:00
|
|
|
public event TargetEventHandler Change {
|
2017-06-16 06:41:38 +00:00
|
|
|
add => AddEventListener ("change", value);
|
|
|
|
remove => RemoveEventListener ("change", value);
|
|
|
|
}
|
|
|
|
|
2017-12-10 23:07:33 +00:00
|
|
|
public event TargetEventHandler Input {
|
2017-12-09 21:19:32 +00:00
|
|
|
add => AddEventListener ("input", value);
|
|
|
|
remove => RemoveEventListener ("input", value);
|
|
|
|
}
|
|
|
|
|
2017-06-16 06:41:38 +00:00
|
|
|
public Select ()
|
|
|
|
: base ("select")
|
|
|
|
{
|
2017-12-09 21:19:32 +00:00
|
|
|
// Subscribe to the change event so we always get up-to-date values
|
2017-12-10 23:07:33 +00:00
|
|
|
Change += (s, e) => { };
|
2017-12-09 21:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddOption (string label, string value)
|
|
|
|
{
|
|
|
|
AppendChild (new Option { Label = label, Value = value });
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnChildInsertedBefore (Node newChild, Node referenceChild)
|
|
|
|
{
|
|
|
|
base.OnChildInsertedBefore (newChild, referenceChild);
|
|
|
|
if (string.IsNullOrEmpty (val) && newChild is Option o && !string.IsNullOrEmpty (o.Value)) {
|
|
|
|
val = o.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool TriggerEventFromMessage (Message message)
|
|
|
|
{
|
|
|
|
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input")) {
|
|
|
|
val = message.Value != null ? Convert.ToString (message.Value) : "";
|
|
|
|
}
|
|
|
|
return base.TriggerEventFromMessage (message);
|
2017-06-16 06:41:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|