ampersand-input-view
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -103,2 +103,3 @@ /*$AMPERSAND_VERSION*/ | ||
valid: { | ||
cache: false, | ||
deps: ['inputValue'], | ||
@@ -138,3 +139,3 @@ fn: function () { | ||
} | ||
this.inputValue = this.input.value; | ||
this.inputValue = this.clean(this.input.value); | ||
if (!skipValidation && !this.getErrorMessage()) { | ||
@@ -141,0 +142,0 @@ this.shouldValidate = true; |
{ | ||
"name": "ampersand-input-view", | ||
"description": "A view module for intelligently rendering and validating input. Works well with ampersand-form-view.", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "browserify": { |
@@ -42,2 +42,16 @@ var test = require('tape'); | ||
test('initialize with number value and type perserved after render', function (t) { | ||
var position = 1; | ||
var input = new InputView({ | ||
name: 'position', | ||
value: position, | ||
type: 'number' | ||
}); | ||
input.render(); | ||
t.equal(input.value, position); | ||
t.end(); | ||
}); | ||
test('can initialize with template without having to extend', function (t) { | ||
@@ -375,1 +389,36 @@ var input = new InputView({ | ||
}); | ||
test('input that is dependent on another', function (t) { | ||
var inputOne = new InputView({ | ||
name: 'foo', | ||
required: true | ||
}); | ||
var inputTwo = new InputView({ | ||
name: 'bar', | ||
required: false, | ||
tests: [ | ||
function () { | ||
if (inputOne.valid) { | ||
return 'Not valid'; | ||
} | ||
} | ||
] | ||
}); | ||
inputOne.render(); | ||
inputTwo.render(); | ||
var inputElement = inputTwo.el.querySelector('input'); | ||
var messageContainer = inputTwo.el.querySelector('[data-hook=message-container]'); | ||
t.notOk(inputOne.valid); | ||
t.ok(inputTwo.valid); | ||
inputOne.setValue('something'); | ||
// Since the only thing parent form evaluates on submit is the valid entry, | ||
// we can simulated that by evaluating valid on both | ||
t.ok(inputOne.valid); | ||
t.notOk(inputTwo.valid); | ||
t.ok(isHidden(messageContainer), 'Message should not be visible'); | ||
t.notOk(hasClass(inputElement, 'input-invalid'), 'Does not have invalid class'); | ||
t.notOk(hasClass(inputElement, 'input-valid'), 'Doest not have valid class'); | ||
t.end(); | ||
}); |
35506
576