Skip to content

Commit

Permalink
Improve can-validate demo
Browse files Browse the repository at this point in the history
Refactored formatErrors helper to handle use case for demo. Switched to using `errors` method instead of `testSet`.  Found a bug in can-define-validate-validatejs.

- Improved demo file
- Updated package to use can-define-validate-validatejs 0.0.3
  • Loading branch information
Macrofig committed Mar 15, 2017
1 parent 3d0ef60 commit 3a92590
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions demos/can-validate/credit-card.html
Expand Up @@ -24,25 +24,25 @@
<script type="text/stache" id="demo-html">
<form>
<div>
<label>Credit Card Number <small class="has-errors">{{formatErrors(testSet('card', card), 'object').card.join(', ')}}</small></label>
<label>Credit Card Number <small class="has-errors">{{formatErrors(this, 'card').join(', ')}}</small></label>
<input
class="form-control {{#if formatErrors(testSet('card', card), 'object').card.length}}has-errors{{/if}}"
class="form-control {{#if formatErrors(this, 'card').length}}has-errors{{/if}}"
type="text"
{($value)}="card"
placeholder="XXXX-XXXX-XXXX-XXXX">
</div>
<div>
<label>Expiration Month <small class="has-errors">{{formatErrors(testSet('month', month), 'object').month.join(', ')}}</small></label>
<label>Expiration Month <small class="has-errors">{{formatErrors(this, 'month').join(', ')}}</small></label>
<input
class="form-control {{#if formatErrors(testSet('month', month), 'object').month.length}}has-errors{{/if}}"
class="form-control {{#if formatErrors(this, 'month').length}}has-errors{{/if}}"
type="text"
{($value)}="month"
placeholder="XX">
</div>
<div>
<label>Expiration Year <small class="has-errors">{{formatErrors(testSet('year', year), 'object').year.join(', ')}}</small></label>
<label>Expiration Year <small class="has-errors">{{formatErrors(this, 'year').join(', ')}}</small></label>
<input
class="form-control {{#if formatErrors(testSet('year', year), 'object').year.length}}has-errors{{/if}}"
class="form-control {{#if formatErrors(this, 'year').length}}has-errors{{/if}}"
type="text"
{($value)}="year"
placeholder="XXXX">
Expand All @@ -57,9 +57,9 @@
var formatErrors = require("can-validate").formatErrors;
require("can-stache-converters");

stache.registerHelper('formatErrors', function (errors, format) {
errors = typeof errors === 'function' ? errors() : errors;
return formatErrors(errors, format);
stache.registerHelper('formatErrors', function (vm, key) {
var errors = formatErrors(vm.errors(key), 'object');
return errors ? errors[key]: [];
});

var CreditCard = DefineMap.extend({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -49,7 +49,7 @@
"can-control": "3.0.7",
"can-define": "1.0.17",
"can-define-stream": "0.0.7",
"can-define-validate-validatejs": "0.0.2",
"can-define-validate-validatejs": "0.0.3",
"can-ejs": "3.0.4",
"can-event": "3.1.1",
"can-fixture": "1.0.13",
Expand Down

0 comments on commit 3a92590

Please sign in to comment.