mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 17:06:01 +08:00
FIX: forces boolean when content is only "true" && "false"
This commit is contained in:
@ -69,7 +69,7 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{combo-box valueAttribute="value" content=availableSorts value=category.sort_order none="category.sort_options.default"}}
|
{{combo-box valueAttribute="value" content=availableSorts value=category.sort_order none="category.sort_options.default"}}
|
||||||
{{#unless isDefaultSortOrder}}
|
{{#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}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -79,7 +79,7 @@ export default SelectKitComponent.extend({
|
|||||||
shouldDisplayFilter() { return true; },
|
shouldDisplayFilter() { return true; },
|
||||||
|
|
||||||
_beforeWillComputeValues(values) {
|
_beforeWillComputeValues(values) {
|
||||||
return values.map(v => this._castInteger(v === "" ? null : v));
|
return values.map(v => this._cast(v === "" ? null : v));
|
||||||
},
|
},
|
||||||
willComputeValues(values) { return values; },
|
willComputeValues(values) { return values; },
|
||||||
computeValues(values) { return values; },
|
computeValues(values) { return values; },
|
||||||
|
@ -62,6 +62,7 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
|
|||||||
horizontalOffset: 0,
|
horizontalOffset: 0,
|
||||||
fullWidthOnMobile: false,
|
fullWidthOnMobile: false,
|
||||||
castInteger: false,
|
castInteger: false,
|
||||||
|
castBoolean: false,
|
||||||
allowAny: false,
|
allowAny: false,
|
||||||
allowInitialValueMutation: false,
|
allowInitialValueMutation: false,
|
||||||
content: null,
|
content: null,
|
||||||
@ -169,7 +170,7 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
|
|||||||
}
|
}
|
||||||
|
|
||||||
let computedContentItem = {
|
let computedContentItem = {
|
||||||
value: this._castInteger(this.valueForContentItem(contentItem)),
|
value: this._cast(this.valueForContentItem(contentItem)),
|
||||||
name: name || this._nameForContent(contentItem),
|
name: name || this._nameForContent(contentItem),
|
||||||
locked: false,
|
locked: false,
|
||||||
created: options.created || false,
|
created: options.created || false,
|
||||||
|
@ -63,7 +63,7 @@ export default SelectKitComponent.extend({
|
|||||||
switch (typeof value) {
|
switch (typeof value) {
|
||||||
case "string":
|
case "string":
|
||||||
case "number":
|
case "number":
|
||||||
return this._castInteger(value === "" ? null : value);
|
return this._cast(value === "" ? null : value);
|
||||||
default:
|
default:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,19 @@ export default Ember.Mixin.create({
|
|||||||
return !isNaN(parseFloat(input)) && isFinite(input);
|
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) {
|
_castInteger(value) {
|
||||||
if (this.get("castInteger") && Ember.isPresent(value) && this._isNumeric(value)) {
|
if (this.get("castInteger") && Ember.isPresent(value) && this._isNumeric(value)) {
|
||||||
return parseInt(value, 10);
|
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', {
|
componentTest('supports keyboard events', {
|
||||||
template: '{{single-select content=content filterable=true}}',
|
template: '{{single-select content=content filterable=true}}',
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user