-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
postbacki handlers: Fix knockout context access in value bindings
Fixes accesses to parent (or higher) knockout contexts or view models. It is necessary to call the AssignParameters function recursively on default assignments of the parent VM/context parameters.
- Loading branch information
Showing
7 changed files
with
147 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Globalization; | ||
using System.Threading.Tasks; | ||
using CheckTestOutput; | ||
using DotVVM.Framework.Compilation; | ||
using DotVVM.Framework.Controls; | ||
using DotVVM.Framework.Tests.Binding; | ||
using DotVVM.Framework.ViewModel; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using DotVVM.Framework.Testing; | ||
using System.Security.Claims; | ||
using System.Collections; | ||
using DotVVM.Framework.Binding; | ||
using DotVVM.Framework.Compilation.ControlTree; | ||
using DotVVM.Framework.Hosting; | ||
|
||
namespace DotVVM.Framework.Tests.ControlTests | ||
{ | ||
[TestClass] | ||
public class PostbackHandlerTests | ||
{ | ||
static readonly ControlTestHelper cth = new ControlTestHelper(config: config => { | ||
}); | ||
readonly OutputChecker check = new OutputChecker("testoutputs"); | ||
|
||
|
||
[TestMethod] | ||
public async Task ButtonHandlers() | ||
{ | ||
var r = await cth.RunPage(typeof(BasicTestViewModel), """ | ||
<!-- suppress postback --> | ||
<dot:Button DataContext={value: Nested} Click={staticCommand: 0} Text="Test supress"> | ||
<Postback.Handlers> | ||
<dot:SuppressPostBackHandler Suppress={value: _parent.Integer > 100 || SomeString.Length < 5} /> | ||
</Postback.Handlers> | ||
</dot:Button> | ||
<!-- confirm --> | ||
<dot:Button DataContext={value: Nested} Click={staticCommand: 0} Text="Test confirm"> | ||
<Postback.Handlers> | ||
<dot:ConfirmPostBackHandler Message={value: $"String={_root.String} SomeString={SomeString}"} /> | ||
</Postback.Handlers> | ||
</dot:Button> | ||
""" | ||
); | ||
|
||
check.CheckString(r.FormattedHtml, fileExtension: "html"); | ||
} | ||
|
||
public class BasicTestViewModel: DotvvmViewModelBase | ||
{ | ||
public int Integer { get; set; } = 123; | ||
public bool Boolean { get; set; } = false; | ||
public string String { get; set; } = "some-string"; | ||
|
||
public TestViewModel3 Nested { get; set; } = new TestViewModel3 { SomeString = "a" }; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Tests/ControlTests/testoutputs/PostbackHandlerTests.ButtonHandlers.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
|
||
<!-- suppress postback --> | ||
<!-- ko with: Nested --> | ||
<input onclick="dotvvm.applyPostbackHandlers((options) => { | ||
0; | ||
},this,[["suppress",(c,d)=>({suppress:c.$parent.Integer() > 100 || d.SomeString()?.length < 5})]]).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;" type="button" value="Test supress"> | ||
<!-- /ko --> | ||
<!-- confirm --> | ||
<!-- ko with: Nested --> | ||
<input onclick="dotvvm.applyPostbackHandlers((options) => { | ||
0; | ||
},this,[["confirm",(c,d)=>({message:dotvvm.translations.string.format("String={0} SomeString={1}", [ | ||
c.$parent.String() | ||
, d.SomeString() | ||
])})]]).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;" type="button" value="Test confirm"> | ||
<!-- /ko --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters