Ticket #259: updateOptions_default.patch

File updateOptions_default.patch, 4.8 KB (added by sravyts, 2 years ago)

patch with default implementation for the updateOptions function

  • kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/basic-controls.js

     
    276276    } 
    277277 
    278278    /** 
    279      * SelectionControl options can depend on values of other controls, this method will register the necessary handler to listen to 
    280      * the valueChanged events of those controls. 
    281      */ 
    282     SelectionControl.prototype.initEventWiring = function() { 
    283  
    284         var options = this.options; 
    285         if (options.toShare() && options.initEventWiringDone) 
    286             return; // no need to re-init shared options, avoiding multiple updates when one suffices 
    287          
    288         // in all other cases we should loop over dependency-controls 
    289         // and register a context-update callback on the value-change-event of each of them 
    290         var depends = this.depends; 
    291         var context = {}; 
    292         for ( var name in depends) { 
    293             var path = depends[name]; 
    294             var control = this.findControl(path); 
    295             context[name] = control.getValue(); 
    296             var updateContext = function( event) { 
    297  
    298                 options.putContext(name, control.getValue()); 
    299             } 
    300             control.valueChanged(updateContext); 
    301             options.putContext(context); // at least trigger reading the dependent context once 
    302         } 
    303          
    304         options.initEventWiringDone = true; 
    305     } 
    306  
    307     /** 
    308279     * Handle the changed options on the type level, by adapting the HTML/control 
    309280     */ 
    310281    SelectionControl.prototype.updateOptions = function( userValues, labels) { 
  • kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js

     
    833833     
    834834    /** 
    835835     * Perform control specific HTML updating of options 
     836     * 
     837     * Default implementation: use the first value to set the value for this control. 
    836838     * @param {Array} values Option values 
    837839     * @param {Array} labels Option labels 
    838840     */ 
    839841    Control.prototype.updateOptions = function(values, labels){ 
    840      
     842 
     843        var value = values[0]; 
     844         
     845        value = value || this.getValue(); 
     846         
     847        var noValidation = (this.valueState == kf.Control.STATE_INIT); 
     848        this.setValue(value, noValidation); 
    841849    } 
    842850     
    843851     
     
    913921        // register event-wiring to happen when form completes 
    914922        this.getForm().initComplete(function(){ 
    915923         
    916             me.initEventWiring(); 
     924            me._initEventWiring(); 
    917925        }); 
    918926    } 
    919927     
     
    926934     
    927935    } 
    928936     
     937    Control.prototype._initEventWiring = function(){ 
     938        var options = this.options; 
     939        if(options){ 
     940            if (options.toShare() && options.initEventWiringDone) 
     941                return; // no need to re-init shared options, avoiding multiple updates when one suffices 
     942             
     943            // in all other cases we should loop over dependency-controls 
     944            // and register a context-update callback on the value-change-event of each of them 
     945            var depends = this.depends; 
     946            var context = {}; 
     947            for ( var name in depends) { 
     948                var path = depends[name]; 
     949                var control = this.findControl(path); 
     950                context[name] = control.getValue(); 
     951                var updateContext = function( event) { 
     952 
     953                    options.putContext(name, control.getValue()); 
     954                } 
     955                control.valueChanged(updateContext); 
     956                options.putContext(context); // at least trigger reading the dependent context once 
     957            } 
     958             
     959            options.initEventWiringDone = true; 
     960        } 
     961         
     962        this.initEventWiring(); 
     963    } 
     964     
    929965    /** 
    930966     * Perform control specific event-wiring allowing to listen to events of other controls in the form. 
    931967     * 
    932968     * @see #_initEvents 
    933969     */ 
    934970    Control.prototype.initEventWiring = function(){ 
    935      
     971         
    936972    } 
    937973     
    938974    /** 
  • kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/field.js

     
    260260    Options.prototype.parseOptions = function( data) { 
    261261 
    262262        data = data || []; 
     263         
     264        if (data.constructor != Array) { 
     265            data = [data]; 
     266        } 
     267         
    263268        // loop through options and build value and label arrays 
    264269        var last = data.length; 
    265270        var values = [];