Skip to content

Commit

Permalink
fix(select): improve value comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Mar 7, 2016
1 parent 5d9b169 commit b967b1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions ionic/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {NG_VALUE_ACCESSOR} from 'angular2/common';
import {Alert} from '../alert/alert';
import {Form} from '../../util/form';
import {Item} from '../item/item';
import {merge, isTrueProperty, isBlank} from '../../util/util';
import {merge, isTrueProperty, isBlank, isCheckedProperty} from '../../util/util';
import {NavController} from '../nav/nav-controller';
import {Option} from '../option/option';

Expand Down Expand Up @@ -310,7 +310,10 @@ export class Select {
if (this._options) {
this._options.toArray().forEach(option => {
// check this option if the option's value is in the values array
option.checked = (this._values.indexOf(option.value) > -1);
option.checked = this._values.some(selectValue => {
return isCheckedProperty(selectValue, option.value);
});

if (option.checked) {
this._texts.push(option.text);
}
Expand Down Expand Up @@ -371,7 +374,13 @@ export class Select {
/**
* @private
*/
onChange(_) {}
onChange(val: any) {
// onChange used when there is not an ngControl
console.debug('select, onChange w/out ngControl', val);
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
this._updOpts();
this.onTouched();
}

/**
* @private
Expand Down
2 changes: 1 addition & 1 deletion ionic/components/select/test/multiple-value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class E2EPage {

this.authForm = new ControlGroup({
name: new Control(''),
select: new Control('')
select: new Control([1, '3'])
});
}

Expand Down

0 comments on commit b967b1e

Please sign in to comment.