Hi, I want to override existing function setMasterValue of webix.ui.popup from webix javascript into seperate js file so that original function is not hampered and to make sure my custom setMasterValue gets called. I am not pretty sure how should I go about it.
Hi,
You can try the following:
webix.protoUI({
name:"suggest",
setMasterValue: function(data, refresh){
// your code
}
},webix.ui.suggest);
Hi Maria, thanks for the reply I have tried this but still it is the default setMasterValue thats getting called. And one more thing, should not that be webix.ui.popup as a base component instead of webix.ui.suggest? I am not too sure though
Hi,
setMasterValue is the method of Suggest. “popup” view does not have such a method. Locally the solution works (try to open suggest and select an option):
Hi Maria,I have webix 2.1.0 and in there setMasterValue is the method in webix.ui.popup. And not sure is this the reason I am not able to extend that base method setMasterValue. Thanks in advance
Hi,
setMasterValue was not a method of “popup” view. Locally the solution works in old Webix version.
Hi… Is possible to call the overridden method inside the overriding method?
In the example above, is it possible to call the original webix.ui.suggest.prototype.setMasterValue() and then add custom code?
I managed to find a way to access the overridden method:
http://webix.com/snippet/880c9712
But I am not sure if this has any disadvantages.
Is there a better way?
Thanks in advance!
Thanks, Maria…
I know I can create a new view but I prefer to change/add to the behavior of the original view.
In this example, I want to add to the behavior of webix.ui.suggest instead of creating a new view because if I create a new view (with a different name), then I would have to change text, richselect, combo to make them use “mysuggest”.
I extend original views this way: http://webix.com/snippet/b258fcea
Hi @Maria I tried to copy your way of overwriting the setMasterValue function to overwrite the filter function but it didn’t work.
I’m aware I could do it directly in the combo liek described here Advanced Configuration of Popup Selectors of Interacting with Users, Controls Guide Webix Docs but I’m aiming to create a generic suggest which can be reused. The idea is that the filter function check whether the combo has the attribute “filterValue” set. If so use this property instead of “value”, otherwise use value.
Here is a snippet with a simple combo where I just try to overwrite the filter with a custom suggest https://snippet.webix.com/igmgg9dt
Here is a mockup of the intended use: Code Snippet
Hello @534h144k ,
As a solution, you define filter
through defaults
properties:
webix.protoUI({
name:"csuggest",
defaults:{
//set of default properties
filter:function(item,value){
/*your code*/
}
},
}, webix.ui.suggest))
Please take a look at the next snippet:
https://snippet.webix.com/piy9jxg2
Good morning @annazankevich thank you for the brillaint solution. How does one know whether to define things like this directly as an attribute like setMasterValue or via the defualts?
Hello @534h144k ,
It depends on the initial requirements. Please, note that setMasterValue
does not overwrite the filter function. The method is responsible for setting the value of the suggest in this case.
The defaults
property is just a property should be used in only for static settings ( these settings set by default).
And since in your case, you needed to create a generic suggest with custom filtering function that can be reused, this was done through the defaults
property.
But you can also redefine filter like:
https://snippet.webix.com/556oc0he