mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: forces boolean when content is only "true" && "false"
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user