Fix clearing the value property on inputs
This commit is contained in:
parent
50a4e7f221
commit
62533cd175
|
@ -12,9 +12,10 @@ namespace Ooui
|
||||||
set => SetAttributeProperty ("type", value);
|
set => SetAttributeProperty ("type", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string val = "";
|
||||||
public string Value {
|
public string Value {
|
||||||
get => GetStringAttribute ("value", "");
|
get => val;
|
||||||
set => SetAttributeProperty ("value", value ?? "");
|
set => SetProperty (ref val, value ?? "", "value");
|
||||||
}
|
}
|
||||||
|
|
||||||
public double NumberValue {
|
public double NumberValue {
|
||||||
|
@ -78,12 +79,15 @@ namespace Ooui
|
||||||
protected override bool TriggerEventFromMessage (Message message)
|
protected override bool TriggerEventFromMessage (Message message)
|
||||||
{
|
{
|
||||||
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input" || message.Key == "keyup")) {
|
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input" || message.Key == "keyup")) {
|
||||||
// Don't need to notify here because the base implementation will fire the event
|
|
||||||
if (Type == InputType.Checkbox) {
|
if (Type == InputType.Checkbox) {
|
||||||
UpdateBooleanAttributeProperty ("checked", message.Value != null ? Convert.ToBoolean (message.Value) : false, "IsChecked");
|
UpdateBooleanAttributeProperty ("checked", message.Value != null ? Convert.ToBoolean (message.Value) : false, "IsChecked");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
UpdateAttributeProperty ("value", message.Value != null ? Convert.ToString (message.Value) : "", "Value");
|
var v = message.Value != null ? Convert.ToString (message.Value) : "";
|
||||||
|
if (val != v) {
|
||||||
|
val = v;
|
||||||
|
OnPropertyChanged ("Value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return base.TriggerEventFromMessage (message);
|
return base.TriggerEventFromMessage (message);
|
||||||
|
|
|
@ -47,9 +47,12 @@ namespace Ooui
|
||||||
|
|
||||||
protected override bool TriggerEventFromMessage (Message message)
|
protected override bool TriggerEventFromMessage (Message message)
|
||||||
{
|
{
|
||||||
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input")) {
|
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input" || message.Key == "keyup")) {
|
||||||
// Don't need to notify here because the base implementation will fire the event
|
var v = message.Value != null ? Convert.ToString (message.Value) : "";
|
||||||
val = message.Value != null ? Convert.ToString (message.Value) : "";
|
if (val != v) {
|
||||||
|
val = v;
|
||||||
|
OnPropertyChanged ("Value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return base.TriggerEventFromMessage (message);
|
return base.TriggerEventFromMessage (message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
#if NUNIT
|
||||||
|
using NUnit.Framework;
|
||||||
|
using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
|
||||||
|
using TestMethodAttribute = NUnit.Framework.TestCaseAttribute;
|
||||||
|
#else
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using Ooui;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class InputTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void ValuePropertyChangedOnReceiver ()
|
||||||
|
{
|
||||||
|
var e = new Ooui.Input ();
|
||||||
|
var count = 0;
|
||||||
|
e.PropertyChanged += (s, ev) => {
|
||||||
|
if (ev.PropertyName == "Value")
|
||||||
|
count++;
|
||||||
|
};
|
||||||
|
e.Receive (new Message {
|
||||||
|
MessageType = MessageType.Event,
|
||||||
|
TargetId = e.Id,
|
||||||
|
Key = "change",
|
||||||
|
Value = "woo",
|
||||||
|
});
|
||||||
|
Assert.AreEqual (1, count);
|
||||||
|
Assert.AreEqual (e.Value, "woo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue