EasyUI Forum
April 19, 2024, 01:39:34 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: cloning a control to a new control.  (Read 8648 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: May 21, 2020, 02:16:43 AM »

Code:
$.fn.multibox = $.fn.combo;

I want to create a new object that inherits all of the properties, methods etc of the combo, and then modify it adding new methods etc.

I do not want these changes to be reflected in the original combo object.

I believe that the above will create an alias to combo, and any changes to multibox will also appy to combo ??

« Last Edit: July 28, 2020, 06:25:02 PM by devnull » Logged

-- Licensed User --
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #1 on: May 29, 2020, 08:28:53 PM »

Bump...
Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #2 on: May 30, 2020, 06:29:53 AM »

This is the skeleton to create a new multibox component based on combo.
Code:
(function($){
function create(target){
var state = $.data(target, 'multibox');
var opts = state.options;

$(target).addClass('multibox-f');
$(target).combo($.extend({}, opts, {

}));

}
$.fn.multibox = function(options,param){
if (typeof options == 'string'){
var method = $.fn.multibox.methods[options];
if (method){
return method(this, param);
} else {
return this.combo(options, param);
}
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'multibox');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'multibox', {
options: $.extend({}, $.fn.multibox.defaults, $.fn.combo.parseOptions(this), options)
});
}
create(this);
});
};
$.fn.multibox.defaults = $.extend({}, $.fn.combo.defaults, {
});
$.fn.multibox.methods = {
options: function(jq){
var copts = jq.combo('options');
return $.extend($.data(jq[0], 'multibox').options, {
width: copts.width,
height: copts.height,
originalValue: copts.originalValue,
disabled: copts.disabled,
readonly: copts.readonly
});
}
}
})(jQuery);
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #3 on: May 30, 2020, 05:56:47 PM »

Thanks so much :-)
Logged

-- Licensed User --
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #4 on: July 14, 2020, 05:12:23 PM »

Hi Jarry is it not possible to just do:

Code:
$.fn.multibox = Object.assign($.fn.combo);
Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #5 on: July 14, 2020, 07:56:43 PM »

Hi Jarry is it not possible to just do:

Code:
$.fn.multibox = Object.assign($.fn.combo);

The two plugins 'multibox' and 'combo' will share the same definitions. The new methods added to the multibox will be added to combo too.
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #6 on: July 14, 2020, 11:23:03 PM »

OK, then is it then possible to create a clone() function that will allow me to generically clone any control to a new control ?

This would be very useful :-)


Logged

-- Licensed User --
Tomas
Newbie
*
Posts: 8


View Profile
« Reply #7 on: July 24, 2020, 09:28:44 AM »

How would you call the new control from markup?

Thanks,
Tomas
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #8 on: July 28, 2020, 06:24:48 PM »

You would call it just like you call any other standard control, only using the new control name.
Logged

-- Licensed User --
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #9 on: November 23, 2020, 03:14:17 AM »

@jarry - this multibox control seems to work except for when using form.load() function.

I have created a setValue() function for this control, and for debugging purposes, I logged some text to the console when the setValue() function is called.

If I call this from the chrome javascript console, then the value is updated correctly and I see the text logged to the console, however when I use form.load() the text is not logged to the console and it looks like form.load() does not call setValue() on the control.

Any suggestions on what the cause / fix may be ?

Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #10 on: November 24, 2020, 07:21:10 PM »

Please run the code below to add the 'multibox' component to the form field set.

Code:
<script>
$.parser.plugins.push('multibox');
$.fn.form.defaults.fieldTypes.unshift('multibox');
</script>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!