Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed double sending of onInvalid action #406

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cc5b673
Fixed double sending of onInvalid action
shoxter Jun 29, 2016
5745ed6
Better solution -- other didn't work properly when going from NULL to…
shoxter Jun 29, 2016
90cf27f
Fixed semi-colon
shoxter Jun 29, 2016
73029e9
Paper form complete
shoxter Jun 29, 2016
f987daf
Changed template to represent new container name
shoxter Jun 29, 2016
bb63130
Revert "Changed template to represent new container name"
shoxter Jun 29, 2016
fbb5c6d
Revert "Paper form complete"
shoxter Jun 29, 2016
5f65716
Upgrade ember-cli to v2.6.2 (#413)
dustinfarris Jul 3, 2016
c455e2d
changed paper-select to call onChange instead of setting value direct…
ibarrick Jul 3, 2016
8f2ff9f
Fixed double sending of onInvalid action
shoxter Jun 29, 2016
7604575
Better solution -- other didn't work properly when going from NULL to…
shoxter Jun 29, 2016
09e7d18
Fixed semi-colon
shoxter Jun 29, 2016
55bdfbe
Paper form complete
shoxter Jun 29, 2016
2697bc6
Changed template to represent new container name
shoxter Jun 29, 2016
450125f
Revert "Changed template to represent new container name"
shoxter Jun 29, 2016
d3f3de4
Revert "Paper form complete"
shoxter Jun 29, 2016
fdfc6f1
Merge branch 'fix-input-validation' of https://github.com/shoxter/emb…
shoxter Jul 5, 2016
5ce5962
Input consistency upgrade (#414)
shoxter Jul 5, 2016
2b3a7bd
Fixed double sending of onInvalid action
shoxter Jun 29, 2016
9d1bd59
Better solution -- other didn't work properly when going from NULL to…
shoxter Jun 29, 2016
dca0470
Fixed semi-colon
shoxter Jun 29, 2016
37c9527
Paper form complete
shoxter Jun 29, 2016
aac53c0
Changed template to represent new container name
shoxter Jun 29, 2016
ff0c27d
Revert "Changed template to represent new container name"
shoxter Jun 29, 2016
22b0bd2
Revert "Paper form complete"
shoxter Jun 29, 2016
647957d
Paper form complete
shoxter Jun 29, 2016
fe041f9
Changed template to represent new container name
shoxter Jun 29, 2016
0c24805
Revert "Changed template to represent new container name"
shoxter Jun 29, 2016
74c678d
Revert "Paper form complete"
shoxter Jun 29, 2016
ff9568b
Merge branch 'fix-input-validation' of https://github.com/shoxter/emb…
shoxter Jul 5, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
---
language: node_js
node_js:
- "0.12"
- "4"

sudo: false

cache:
directories:
- node_modules

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary

matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- "npm config set spin false"
- "npm install -g npm@^2"
- npm config set spin false
- npm install -g bower
- npm install phantomjs-prebuilt

install:
- npm install -g bower
- npm install -g phantomjs-prebuilt@2
- npm install
- bower install

script:
- ember try:each
- ember try $EMBER_TRY_SCENARIO test --skip-cleanup
16 changes: 13 additions & 3 deletions addon/components/paper-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, {

didRender() {
this.growTextarea();
// setValue below ensures that the input value is the same as this.value
this.setValue(this.get('value'));
},

willClearRender() {
Expand Down Expand Up @@ -200,15 +202,23 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, {

notifyInvalid() {
let isInvalid = this.get('isInvalid');
if (this.get('lastIsInvalid') !== isInvalid) {
this.sendAction('onInvalid', this.get('isInvalid'));
this.set('lastIsInvalid', this.get('isInvalid'));
let lastIsInvalid = this.get('lastIsInvalid');
let isInvalidChanged = (lastIsInvalid !== isInvalid);
let isNotRedundant = !((lastIsInvalid === null && isInvalid) || (lastIsInvalid && isInvalid === null));
if (isInvalidChanged && isNotRedundant) {
this.sendAction('onInvalid', isInvalid);
this.set('lastIsInvalid', isInvalid);
}
},
setValue(value) {
this.$('input, textarea').val(value);
},

actions: {
handleInput(e) {
this.sendAction('onChange', e.target.value);
// setValue below ensures that the input value is the same as this.value
this.setValue(this.get('value'));
this.growTextarea();
let inputElement = this.$('input').get(0);
this.set('isNativeInvalid', inputElement && inputElement.validity && inputElement.validity.badInput);
Expand Down
4 changes: 2 additions & 2 deletions addon/components/paper-select-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export default PaperMenuAbstract.extend({

actions: {
selectOption(value) {
this.set('value', value);
this.get('onChange')(value);
},
deselectOption() {
this.set('value', null);
this.get('onChange')(null);
}
},

Expand Down
2 changes: 0 additions & 2 deletions app/templates/components/paper-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
class="md-input {{if isInvalid "ng-invalid"}} {{if isTouched "ng-dirty"}}"
id={{inputElementId}}
placeholder={{placeholder}}
value={{value}}
disabled={{disabled}}
autofocus={{autofocus}}
onfocus={{onFocus}}
Expand All @@ -38,7 +37,6 @@
id={{inputElementId}}
placeholder={{placeholder}}
type={{type}}
value={{value}}
disabled={{disabled}}
autofocus={{autofocus}}
onfocus={{onFocus}}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/paper-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
{{paper-icon icon class=icon-class}}
{{/if}}

{{#paper-select-core placeholder=placeholder value=value disabled=disabled getItems=getItems itemLabelCallback=itemLabelCallback as |items|}}
{{#paper-select-core placeholder=placeholder value=value disabled=disabled onChange=onChange getItems=getItems itemLabelCallback=itemLabelCallback as |items|}}
{{yield items}}
{{/paper-select-core}}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-paper",
"dependencies": {
"ember": "2.5.1",
"ember": "2.6.1",
"ember-cli-shims": "0.1.1",
"ember-cli-test-loader": "0.2.2",
"ember-qunit-notifications": "0.1.0",
Expand Down
52 changes: 52 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
/*jshint node:true*/
module.exports = {
scenarios: [
{
name: 'default',
bower: {
dependencies: { }
}
},
{
name: 'ember-1.13',
bower: {
dependencies: {
'ember': '~1.13.0'
},
resolutions: {
'ember': '~1.13.0'
}
}
},
{
name: 'ember-release',
bower: {
dependencies: {
'ember': 'components/ember#release'
},
resolutions: {
'ember': 'release'
}
}
},
{
name: 'ember-beta',
bower: {
dependencies: {
'ember': 'components/ember#beta'
},
resolutions: {
'ember': 'beta'
}
}
},
{
name: 'ember-canary',
bower: {
dependencies: {
'ember': 'components/ember#canary'
},
resolutions: {
'ember': 'canary'
}
}
}
]
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"broccoli-static-compiler": "~0.2.1",
"ember-ajax": "0.7.1",
"ember-cli": "2.4.3",
"ember-ajax": "^2.0.1",
"ember-cli": "2.6.2",
"ember-cli-app-version": "^1.0.0",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-github-pages": "^0.1.0",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "^1.0.0",
"ember-cli-qunit": "^1.4.0",
"ember-cli-release": "0.2.8",
"ember-cli-release": "^0.2.9",
"ember-cli-sass": "^5.2.1",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-code-snippet": "1.3.0",
"ember-cp-validations": "2.6.1",
"ember-data": "^2.4.2",
"ember-data": "^2.6.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.5",
Expand All @@ -48,7 +49,6 @@
"ember-resolver": "^2.0.3",
"ember-suave": "2.0.1",
"ember-transition-helper": "0.0.6",
"ember-try": "^0.2.2",
"liquid-fire": "0.23.1",
"loader.js": "^4.0.1"
},
Expand Down
15 changes: 9 additions & 6 deletions tests/helpers/module-for-acceptance.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// https://github.com/DockYard/ember-suave/issues/109
// jscs:disable
import { module } from 'qunit';
import Ember from 'ember';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';

const { RSVP: { Promise } } = Ember;

export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();

if (options.beforeEach) {
options.beforeEach(...arguments);
return options.beforeEach.apply(this, arguments);
}
},

afterEach() {
if (options.afterEach) {
options.afterEach(...arguments);
}

destroyApp(this.application);
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return Promise.resolve(afterEach).then(() => destroyApp(this.application));
}
});
}
// jscs:enable
33 changes: 33 additions & 0 deletions tests/integration/components/paper-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,36 @@ test('the `onChange` action is mandatory for paper-input', function(assert) {
`);
}, /`onChange` action/);
});

test('displayed input value matches actual input value', function(assert) {
assert.expect(4);

this.set('value', '');
this.onChange = () => {
this.set('value', '123');
};

this.render(hbs`{{paper-input onChange=onChange value=value}}`);

this.$('input, textarea').val('12345').trigger('input');
assert.equal(this.$('input, textarea').val(), '123', 'input value should be 123');
assert.equal(this.value, '123', 'component value should be 123');

this.$('input, textarea').val('abcdefg').trigger('input');
assert.equal(this.$('input, textarea').val(), '123', 'input values do not match');
assert.equal(this.value, '123', 'component value should be 123');

});

test('displayed input value matches actual input value with no onChange method', function(assert) {
assert.expect(2);

this.set('value', 'foo');

this.render(hbs`{{paper-input onChange=null value=value}}`);

this.$('input, textarea').val('12345').trigger('input');
assert.equal(this.$('input, textarea').val(), 'foo', 'input value should be `foo` (component value)');
assert.equal(this.get('value'), 'foo', 'component value should be foo');

});