• function

Reconfigure a control.



  1. newOptions {Object}

    Options to merge into the current options.

  2. options {Object}

    A list of options to merge with this.options. Often this method is called by the jQuery helper function.

Update extends options with the options argument and rebinds all events. It re-configures the control.

For example, the following control wraps a recipe form. When the form is submitted, it creates the recipe on the server. When the recipe is created, it resets the form with a new instance.

var Creator = can.Control({
    "{recipe} created" : function(){
        this.update({recipe : new Recipe()});
        this.element.find("[type=submit]").val("Create Recipe")
    "submit" : function(el, ev){
        var recipe = this.options.recipe;
        recipe.attrs( this.element.formParams() );

$('#createRecipes').creator({ recipe : new Recipe() })

Update is called if a control's plugin helper is called with the plugin options on an element that already has a control instance of the same type. If you want to implement your own update method make sure to call the old one either using the super plugin or by calling can.Control.prototype.update.apply(this, arguments);. For example, you can change the content of the control element every time the options change:

var Plugin = can.Control({
    pluginName: 'myPlugin'
}, {
    init : function(el, options) {
    this.updateCount = 0;
        text : 'Initialized'
update : function(options) {
    // Call the can.Control update first.
    // Use this._super when using can/construct/super
    can.Control.prototype.update.call(this, options);
    this.element.html(this.options.text + ' ' +
        (++this.updateCount) + ' times');

// Initialized. Updated 1 times

$('#control').myPlugin({ text : 'Calling update. Updated' });
// Calling update. Updated 2 times