-
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.
added simple client extender sample - password strength checker
- Loading branch information
Showing
6 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
src/DotVVM.Samples.BasicSamples/Scripts/ClientExtenders.js
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,42 @@ | ||
ko.extenders.passwordStrength = function (target, overrideMessage) | ||
{ | ||
//add some sub-observables to our observable | ||
target.passwordStrengthMessage = ko.observable(); | ||
|
||
//define a function to do password strength test | ||
function testPassword(newValue) { | ||
|
||
// very simple password test - checks the string length only | ||
|
||
var val = newValue || ""; | ||
if (val.length === 0) | ||
{ | ||
target.passwordStrengthMessage("Enter password"); | ||
} | ||
else | ||
{ | ||
target.passwordStrengthMessage("Poor"); | ||
} | ||
|
||
if (val.length > 5) { | ||
target.passwordStrengthMessage("Good"); | ||
} | ||
|
||
if (val.length > 8) { | ||
target.passwordStrengthMessage("Super"); | ||
} | ||
|
||
if (val.length > 12) { | ||
target.passwordStrengthMessage("Excelent"); | ||
} | ||
} | ||
|
||
//initial validation | ||
testPassword(target()); | ||
|
||
//validate whenever the value changes | ||
target.subscribe(testPassword); | ||
|
||
//return the original observable | ||
return target; | ||
}; |
26 changes: 26 additions & 0 deletions
26
...mples.BasicSamples/ViewModels/FeatureSamples/ClientExtenders/PasswordStrengthViewModel.cs
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,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.Binding; | ||
using DotVVM.Framework.ViewModel; | ||
|
||
namespace DotVVM.Samples.BasicSamples.ViewModels.FeatureSamples.ClientExtenders | ||
{ | ||
public class PasswordStrengthViewModel : DotvvmViewModelBase | ||
{ | ||
[ClientExtender("passwordStrength", false)] | ||
public string Password { get; set; } | ||
|
||
|
||
public override Task Init() | ||
{ | ||
this.Context.ResourceManager.AddRequiredScriptFile("extenders", "~/Scripts/ClientExtenders.js", DotVVM.Framework.ResourceManagement.ResourceConstants.KnockoutJSResourceName); | ||
return base.Init(); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
17 changes: 17 additions & 0 deletions
17
...DotVVM.Samples.BasicSamples/Views/FeatureSamples/ClientExtenders/PasswordStrength.dothtml
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,17 @@ | ||
@viewModel DotVVM.Samples.BasicSamples.ViewModels.FeatureSamples.ClientExtenders.PasswordStrengthViewModel, DotVVM.Samples.BasicSamples | ||
|
||
<!DOCTYPE html> | ||
|
||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>Password strength indicator - simple Knockout extender sample</h1> | ||
<dot:TextBox ID="passwordTextBox" Text="{value: Password}" UpdateTextAfterKeydown="true" Type="Password"></dot:TextBox> | ||
<span data-bind="text: $data.Password.passwordStrengthMessage"></span> | ||
</body> | ||
</html> | ||
|
||
|