FIX: brings back castInteger as a safer migration path for sk2 (#8966)

FIX: brings back castInteger as a safer migration path for sk2 (#8966)

diff --git a/app/assets/javascripts/admin/templates/components/site-settings/enum.hbs b/app/assets/javascripts/admin/templates/components/site-settings/enum.hbs
index 2612679d72..648e662f8e 100644
--- a/app/assets/javascripts/admin/templates/components/site-settings/enum.hbs
+++ b/app/assets/javascripts/admin/templates/components/site-settings/enum.hbs
@@ -3,7 +3,10 @@
   content=setting.validValues
   value=value
   onChange=(action (mut value))
-  allowAny=setting.allowsNone
+  options=(hash
+    castInteger=true
+    allowAny=setting.allowsNone
+  )
 }}
 
 {{preview}}
diff --git a/app/assets/javascripts/select-kit/components/multi-select.js.es6 b/app/assets/javascripts/select-kit/components/multi-select.js.es6
index 2bb727caf6..42cb8e5229 100644
--- a/app/assets/javascripts/select-kit/components/multi-select.js.es6
+++ b/app/assets/javascripts/select-kit/components/multi-select.js.es6
@@ -80,7 +80,10 @@ export default SelectKitComponent.extend({
   },
 
   selectedContent: computed("value.[]", "content.[]", function() {
-    const value = Ember.makeArray(this.value);
+    const value = Ember.makeArray(this.value).map(v =>
+      this.selectKit.options.castInteger && this._isNumeric(v) ? Number(v) : v
+    );
+
     if (value.length) {
       let content = [];
 
diff --git a/app/assets/javascripts/select-kit/components/select-kit.js.es6 b/app/assets/javascripts/select-kit/components/select-kit.js.es6
index 4b1f896ff8..9eaa205aed 100644
--- a/app/assets/javascripts/select-kit/components/select-kit.js.es6
+++ b/app/assets/javascripts/select-kit/components/select-kit.js.es6
@@ -268,7 +268,8 @@ export default Component.extend(
       limitMatches: null,
       placement: "bottom-start",
       filterComponent: "select-kit/select-kit-filter",
-      selectedNameComponent: "selected-name"
+      selectedNameComponent: "selected-name",
+      castInteger: false
     },
 
     autoFilterable: computed("content.[]", "selectKit.filter", function() {
@@ -961,7 +962,8 @@ export default Component.extend(
         maximum: "options.maximum",
         minimum: "options.minimum",
         i18nPostfix: "options.i18nPostfix",
-        i18nPrefix: "options.i18nPrefix"
+        i18nPrefix: "options.i18nPrefix",
+        castInteger: "options.castInteger"
       };
 
       Object.keys(migrations).forEach(from => {
diff --git a/app/assets/javascripts/select-kit/components/single-select.js.es6 b/app/assets/javascripts/select-kit/components/single-select.js.es6
index 18f2ede6fb..7338d80ecf 100644
--- a/app/assets/javascripts/select-kit/components/single-select.js.es6
+++ b/app/assets/javascripts/select-kit/components/single-select.js.es6
@@ -16,17 +16,23 @@ export default SelectKitComponent.extend({
     if (!isEmpty(this.value)) {
       let content;
 
+      const value =
+        this.selectKit.options.castInteger && this._isNumeric(this.value)
+          ? Number(this.value)
+          : this.value;
+
       if (this.selectKit.valueProperty) {
         content = (this.content || []).findBy(
           this.selectKit.valueProperty,
-          this.value
+          value
         );
+
         return this.selectKit.modifySelection(
-          content || this.defaultItem(this.value, this.value)
+          content || this.defaultItem(value, value)
         );
       } else {
         return this.selectKit.modifySelection(
-          (this.content || []).filter(c => c === this.value)
+          (this.content || []).filter(c => c === value)
         );
       }
     } else {

GitHub sha: 7d94de64

1 Like

This commit appears in #8966 which was merged by @jjaffeux.