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);
|
||||
}
|
||||
|
||||
string val = "";
|
||||
public string Value {
|
||||
get => GetStringAttribute ("value", "");
|
||||
set => SetAttributeProperty ("value", value ?? "");
|
||||
get => val;
|
||||
set => SetProperty (ref val, value ?? "", "value");
|
||||
}
|
||||
|
||||
public double NumberValue {
|
||||
|
@ -78,12 +79,15 @@ namespace Ooui
|
|||
protected override bool TriggerEventFromMessage (Message message)
|
||||
{
|
||||
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) {
|
||||
UpdateBooleanAttributeProperty ("checked", message.Value != null ? Convert.ToBoolean (message.Value) : false, "IsChecked");
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -47,9 +47,12 @@ namespace Ooui
|
|||
|
||||
protected override bool TriggerEventFromMessage (Message message)
|
||||
{
|
||||
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input")) {
|
||||
// Don't need to notify here because the base implementation will fire the event
|
||||
val = message.Value != null ? Convert.ToString (message.Value) : "";
|
||||
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input" || message.Key == "keyup")) {
|
||||
var v = message.Value != null ? Convert.ToString (message.Value) : "";
|
||||
if (val != v) {
|
||||
val = v;
|
||||
OnPropertyChanged ("Value");
|
||||
}
|
||||
}
|
||||
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