# Web Components: model property type "function"?

**URL:** <https://forum.servoy.com/t/web-components-model-property-type-function/19195>\
**Category:** Classic Servoy\
**Created:** [March 31, 2017, 3:00pm UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195 "2017-03-31T15:00:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergei.sheinin](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@sergei.sheinin](https://forum.servoy.com/u/sergei.sheinin)\
**Post date:** [March 31, 2017, 3:00pm UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/1 "2017-03-31T15:00:26Z")

</div>

In integrating web component “TinyMCE” I came across a property type that is “function” according to that component API:

```auto
tinymce.init({
  toolbar: 'mybutton',
  setup: function (editor) {
    editor.addButton('mybutton', {
      text: 'My button',
      icon: false,
      onclick: function () {
        editor.insertContent(' <b>It\'s my button!</b> ');
      }
    });
  },
...
}

```

Above there are two properties: toolbar and setup. It’s all clear with “toolbar”, I define it as a string parameter in .spec file:

```auto
"model": {
    "toolbar": {
      "type": "string",
      "default": "undo redo | etc, etc..."
    },
...
}

```

What is the right way to configure a property of type “function”? I didn’t find a mention of it in the manual. Moreover the aforementioned “setup” function can only be called at time of initialization. It doesn’t appear possible to call “tinymce.init({})” after the component has been initialized.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![sergei.sheinin](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@sergei.sheinin](https://forum.servoy.com/u/sergei.sheinin)\
**Post date:** [April 1, 2017, 5:56am UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/2 "2017-04-01T05:56:07Z")

</div>

I was able to find a workaround for this. It’s very specific to TinyMCE component and one of its features. If interested I may post my solution here.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 1, 2017, 4:36pm UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/3 "2017-04-01T16:36:38Z")

</div>

We are always interested in solutions ![:-)]( "Smile"). Please post!

We also hope that you make the component you are working on available to the community when finished!

---

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [April 2, 2017, 9:22am UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/4 "2017-04-02T09:22:37Z")

</div>

+1

---

<div class="post-metadata">

**Author:** ![sergei.sheinin](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@sergei.sheinin](https://forum.servoy.com/u/sergei.sheinin)\
**Post date:** [April 2, 2017, 5:10pm UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/5 "2017-04-02T17:10:44Z")

</div>

The workaround was quite simple. A function is executed in component controller upon a condition based on setting of a model property:

```auto
controller: function($scope, $element, $attrs, $window) {

    $scope.tinymceOptions = {
    		  .....
    	    setup : function ( editor ) {
    	    	
    	      if (!$scope.model.to_execute_function) return
              else
                 ... function logic..
            }
   }

```

So for example let’s specify a model parameter “to\_execute\_function”: {type:“boolean”}. Thus we don’t need to provide the function body in a web component’s .spec file. Instead it’s written in plain JavaScript with a condition that decides whether to run it or not. I think future versions of Servoy will need to support model parameters like “setup” : {“function”:“”} to make it more straightforward while my workaround seems a bit of a hack.

I’m new to Servoy web components while there is little documentation on types of model parameters NG Client supports. Imo Servoy should support non-basic model parameters of type “function”, “array” and “json”. Unless I’m missing it those types are not yet supported while they are widely used in NG dev. Are there plans to include support for these? In particular support of “array”, “json” and "array

```json
" would be very welcome.

For example like so:

[code]
"model":{
  "my_param": {
      "type" : "array[json]",
      "default": {
            "key": "_mykey",
            "value": "_myvalue",
             "etc": "_myetc"
         }
    }
  }
[/code]

And properties window in Eclipse would then enable developers to add array elements of "my_param" one-by-one.

```

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 2, 2017, 7:36pm UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/6 "2017-04-02T19:36:10Z")

</div>

There is support for all of that. function is “function”, array is “string”, “int”, … or even “yourOwnType”, json is “object”. Have you read this [https://wiki.servoy.com/display/DOCS/Property+Types](https://wiki.servoy.com/display/DOCS/Property+Types) and its sub pages?

---

<div class="post-metadata">

**Author:** ![Gabi\_Boros](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@Gabi\_Boros](https://forum.servoy.com/u/Gabi_Boros)\
**Post date:** [April 3, 2017, 5:39am UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/7 "2017-04-03T05:39:51Z")

</div>

Servoy’s default ‘Html Area’ component is also based on TinyMCE, maybe it can be useful to have a look how it is used there [https://github.com/Servoy/servoy-client … t/htmlarea](https://github.com/Servoy/servoy-client/tree/v82x_branch/servoy_ngclient/war/servoydefault/htmlarea)

---

<div class="post-metadata">

**Author:** ![sergei.sheinin](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@sergei.sheinin](https://forum.servoy.com/u/sergei.sheinin)\
**Post date:** [April 3, 2017, 8:21am UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/8 "2017-04-03T08:21:41Z")

</div>

> patrick:  
> There is support for all of that. function is “function”, array is “string”, “int”, … or even “yourOwnType”, json is “object”. Have you read this [https://wiki.servoy.com/display/DOCS/Property+Types](https://wiki.servoy.com/display/DOCS/Property+Types) and its sub pages?

It worked beautifully! My mistake was in typing “array” in model parameter type.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 3, 2017, 8:26am UTC](https://forum.servoy.com/t/web-components-model-property-type-function/19195/9 "2017-04-03T08:26:51Z")

</div>

> It worked beautifully!

It’s Servoy ![:wink:]( "Wink")
