mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:35:32 +08:00
FIX: forces boolean when content is only "true" && "false"
This commit is contained in:
parent
30fbf6fe81
commit
1be76d066c
|
@ -69,7 +69,7 @@
|
|||
<div class="controls">
|
||||
{{combo-box valueAttribute="value" content=availableSorts value=category.sort_order none="category.sort_options.default"}}
|
||||
{{#unless isDefaultSortOrder}}
|
||||
{{combo-box valueAttribute="value" content=sortAscendingOptions value=category.sort_ascending none="category.sort_options.default"}}
|
||||
{{combo-box castBoolean=true valueAttribute="value" content=sortAscendingOptions value=category.sort_ascending none="category.sort_options.default"}}
|
||||
{{/unless}}
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -79,7 +79,7 @@ export default SelectKitComponent.extend({
|
|||
shouldDisplayFilter() { return true; },
|
||||
|
||||
_beforeWillComputeValues(values) {
|
||||
return values.map(v => this._castInteger(v === "" ? null : v));
|
||||
return values.map(v => this._cast(v === "" ? null : v));
|
||||
},
|
||||
willComputeValues(values) { return values; },
|
||||
computeValues(values) { return values; },
|
||||
|
|
|
@ -62,6 +62,7 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
|
|||
horizontalOffset: 0,
|
||||
fullWidthOnMobile: false,
|
||||
castInteger: false,
|
||||
castBoolean: false,
|
||||
allowAny: false,
|
||||
allowInitialValueMutation: false,
|
||||
content: null,
|
||||
|
@ -169,7 +170,7 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
|
|||
}
|
||||
|
||||
let computedContentItem = {
|
||||
value: this._castInteger(this.valueForContentItem(contentItem)),
|
||||
value: this._cast(this.valueForContentItem(contentItem)),
|
||||
name: name || this._nameForContent(contentItem),
|
||||
locked: false,
|
||||
created: options.created || false,
|
||||
|
|
|
@ -63,7 +63,7 @@ export default SelectKitComponent.extend({
|
|||
switch (typeof value) {
|
||||
case "string":
|
||||
case "number":
|
||||
return this._castInteger(value === "" ? null : value);
|
||||
return this._cast(value === "" ? null : value);
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,19 @@ export default Ember.Mixin.create({
|
|||
return !isNaN(parseFloat(input)) && isFinite(input);
|
||||
},
|
||||
|
||||
_cast(value) {
|
||||
if (value === this.noneValue) return value;
|
||||
return this._castInteger(this._castBoolean(value));
|
||||
},
|
||||
|
||||
_castBoolean(value) {
|
||||
if (this.get("castBoolean") && Ember.isPresent(value) && typeof(value) === "string") {
|
||||
return value === "true";
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
_castInteger(value) {
|
||||
if (this.get("castInteger") && Ember.isPresent(value) && this._isNumeric(value)) {
|
||||
return parseInt(value, 10);
|
||||
|
|
|
@ -232,6 +232,33 @@ componentTest('supports converting select value to integer', {
|
|||
}
|
||||
});
|
||||
|
||||
componentTest('supports converting string as boolean to boolean', {
|
||||
template: '{{single-select value=value content=content castBoolean=true}}',
|
||||
|
||||
beforeEach() {
|
||||
this.set('value', true);
|
||||
this.set('content', [{ id: 'true', name: 'ASC'}, {id: 'false', name: 'DESC' }]);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
this.get('subject').expand();
|
||||
|
||||
andThen(() => assert.equal(this.get('subject').selectedRow().name(), 'ASC') );
|
||||
|
||||
andThen(() => {
|
||||
this.set('value', false);
|
||||
});
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(
|
||||
this.get('subject').selectedRow().name(),
|
||||
'DESC',
|
||||
'it works with dynamic content'
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('supports keyboard events', {
|
||||
template: '{{single-select content=content filterable=true}}',
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user