Преглед на файлове

[spark] Clone the initial values in the ko csv input component

If the csv input component is called with an array of observables the observables will be updated with the internal structure of the csv component, which is not what we want. The error appears after loading a saved notebook containing snippets with some values set for the csv properties, it's caused by the ko mapping plugin creating observables for these values.

This fixes the issue by using the ko mapping toJS function to ensure that no observables are referenced.
Johan Ahlen преди 10 години
родител
ревизия
fa7e8d76a7
променени са 2 файла, в които са добавени 7 реда и са изтрити 2 реда
  1. 1 1
      apps/spark/src/spark/templates/editor_components.mako
  2. 6 1
      desktop/core/src/desktop/templates/ko_components.mako

+ 1 - 1
apps/spark/src/spark/templates/editor_components.mako

@@ -426,7 +426,7 @@ from django.utils.translation import ugettext as _
 <script type="text/html" id="snippet-settings">
   <div class="snippet-settings" data-bind="slideVisible: settingsVisible" style="position: relative; z-index: 100;">
     <div class="snippet-settings-header">
-      <h4><i class="fa fa-cog"></i> Settings</h4>
+      <h4><i class="fa fa-cog"></i> '${ _('Settings') }'</h4>
     </div>
     <div class="snippet-settings-body">
       <form class="form-horizontal">

+ 6 - 1
desktop/core/src/desktop/templates/ko_components.mako

@@ -605,7 +605,12 @@ from django.utils.translation import ugettext as _
         this.placeholder = params.placeholder || '';
         this.inputTemplate = params.inputTemplate || null;
 
-        var initialValues = this.isArray ? this.valueObservable() : this.valueObservable().split(",");
+        var initialValues;
+        if (this.isArray) {
+          initialValues = ko.mapping.toJS(this.valueObservable());
+        } else {
+          initialValues = this.valueObservable() != null ? this.valueObservable().split(",") : [];
+        }
         for (var i = 0; i < initialValues.length; i++) {
           initialValues[i] = { value: ko.observable(initialValues[i].trim()) };
           initialValues[i].value.subscribe(this.updateValueObservable, this);