mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
fix(select): improve value comparisons
This commit is contained in:
@ -4,7 +4,7 @@ import {NG_VALUE_ACCESSOR} from 'angular2/common';
|
|||||||
import {Alert} from '../alert/alert';
|
import {Alert} from '../alert/alert';
|
||||||
import {Form} from '../../util/form';
|
import {Form} from '../../util/form';
|
||||||
import {Item} from '../item/item';
|
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 {NavController} from '../nav/nav-controller';
|
||||||
import {Option} from '../option/option';
|
import {Option} from '../option/option';
|
||||||
|
|
||||||
@ -310,7 +310,10 @@ export class Select {
|
|||||||
if (this._options) {
|
if (this._options) {
|
||||||
this._options.toArray().forEach(option => {
|
this._options.toArray().forEach(option => {
|
||||||
// check this option if the option's value is in the values array
|
// 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) {
|
if (option.checked) {
|
||||||
this._texts.push(option.text);
|
this._texts.push(option.text);
|
||||||
}
|
}
|
||||||
@ -371,7 +374,13 @@ export class Select {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @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
|
* @private
|
||||||
|
@ -26,7 +26,7 @@ class E2EPage {
|
|||||||
|
|
||||||
this.authForm = new ControlGroup({
|
this.authForm = new ControlGroup({
|
||||||
name: new Control(''),
|
name: new Control(''),
|
||||||
select: new Control('')
|
select: new Control([1, '3'])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user