Ticket #259: updateOptions_default.patch
| File updateOptions_default.patch, 4.8 KB (added by sravyts, 2 years ago) |
|---|
-
kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/basic-controls.js
276 276 } 277 277 278 278 /** 279 * SelectionControl options can depend on values of other controls, this method will register the necessary handler to listen to280 * 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 suffices287 288 // in all other cases we should loop over dependency-controls289 // and register a context-update callback on the value-change-event of each of them290 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 once302 }303 304 options.initEventWiringDone = true;305 }306 307 /**308 279 * Handle the changed options on the type level, by adapting the HTML/control 309 280 */ 310 281 SelectionControl.prototype.updateOptions = function( userValues, labels) { -
kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js
833 833 834 834 /** 835 835 * Perform control specific HTML updating of options 836 * 837 * Default implementation: use the first value to set the value for this control. 836 838 * @param {Array} values Option values 837 839 * @param {Array} labels Option labels 838 840 */ 839 841 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); 841 849 } 842 850 843 851 … … 913 921 // register event-wiring to happen when form completes 914 922 this.getForm().initComplete(function(){ 915 923 916 me. initEventWiring();924 me._initEventWiring(); 917 925 }); 918 926 } 919 927 … … 926 934 927 935 } 928 936 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 929 965 /** 930 966 * Perform control specific event-wiring allowing to listen to events of other controls in the form. 931 967 * 932 968 * @see #_initEvents 933 969 */ 934 970 Control.prototype.initEventWiring = function(){ 935 971 936 972 } 937 973 938 974 /** -
kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/field.js
260 260 Options.prototype.parseOptions = function( data) { 261 261 262 262 data = data || []; 263 264 if (data.constructor != Array) { 265 data = [data]; 266 } 267 263 268 // loop through options and build value and label arrays 264 269 var last = data.length; 265 270 var values = [];