NG component pushToServer question

Forum to discuss the new web client version of Servoy.

NG component pushToServer question

Postby steve1376656734 » Thu Oct 01, 2020 10:14 pm

Hi,

I am trying to write an NG component and have a question regarding pushing values to the server.

In my .spec file I have the following property definition:
Code: Select all
{
   "name": "ewscomponents-testcomponent",
   "displayName": "EWS Test",
   "version": 1,
   "definition": "ewscomponents/testcomponent/testcomponent.js",
   "libraries": [ ],

   "model":
   {
      "settings":
      {
         "type": "settingsObject",
         "pushToServer": "shallow",
         "tags": {
            "doc": "The settings for this element"
         },
         "default": { }
      },

      "visible": "visible"
   },

   "types":
   {
      "settingsObject":
      {
         "options":
         {
            "type": "optionsObject",
            "tags": {
               "doc": "The options for the component"
            },
            "default": { }
            
         }
      },

      "optionsObject":
      {
         "sizes":
         {
            "type": "float[]",
            "tags": {
               "doc": "The relative size of each of the options. Specified as an array of numbers"
            },
         },
         "default": { }
      }
   }
}

In the .js file I have a watch on the property using:
Code: Select all
// Watch the sizes
$scope.$watch('model.settings.options.sizes', function(newValue, oldValue) {
   if ($scope.optionsContainer) $scope.optionsContainer.setSizes(newValue);
}, true);

Also in the .js file I have a callback from my client component that is triggered when they end a drag on one of the options:
Code: Select all
onDragEnd: function() {
   if ($scope.split) {
      $scope.model.settings.options.sizes.length = 0;
      $scope.$apply();
      $scope.optionsContainer.getSizes().forEach(function(element, index) {
         $scope.model.settings.options.sizes.push(element);
      });
      $scope.$apply();
   }
}

My issue is that the array of sizes can be changed on the client and I want these changes pushed back to the server. The problem I am getting is that this all works fine as log as the sizes array is empty when the component is initialised but if it already contains values then when the client tries to update the array I get errors on the server:
Code: Select all
ERROR org.sablo.specification.property.CustomJSONPropertyType - Cannot correctly parse custom array property updates/values from browser. Update JSON: {"vEr":2,"u":[{"i":"0"}]} org.json.JSONException: JSONObject["v"] not found.

Can anyone see what I am doing wrong?

Thanks
Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 338
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: NG component pushToServer question

Postby sbutler » Mon Oct 05, 2020 5:51 pm

just a quick guess from glancing at it. Wondering if the "default" of optionsObject needs moved in inside sizes? and maybe changed to []
like

Code: Select all
      "optionsObject":
      {
         "sizes":
         {
            "type": "float[]",
            "tags": {
               "doc": "The relative size of each of the options. Specified as an array of numbers"
            },
            "default": []
         }
      }
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 767
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 22 guests