Changeset 1873 for trunk


Ignore:
Timestamp:
2011-03-15 08:53:20 (14 months ago)
Author:
mpo
Message:

fixes #449. Thanx to Ives for spotting and the elegant testcase.
By introducing a third argument (boolean) to eachChild() method we can specify looping needs to pass also in-active children. This is needed for the special behavior of the case control (who has only one of its value-control children active at any given time)

Location:
trunk/modules/kauri-forms/kauri-forms-framework/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/case.js

    r1863 r1873  
    197197    } 
    198198     
     199    /** 
     200     * Gets all child controls 
     201     * @return object containing all the children 
     202     * @param includeAll boolean indicating if the 'hidden' children of this container should be included (see case-control) 
     203     * @type Object 
     204     */ 
     205    CaseControl.prototype.getChildren = function(includeAll) { 
     206        includeAll = includeAll || false; 
     207        if (includeAll) 
     208            return this._valueControls; 
     209        return 
     210            this["<super.call>"]("getChildren"); 
     211         
     212    } 
    199213     
    200214    /** 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js

    r1869 r1873  
    21082108     * Loops through all children and exectues the passed function in turn with each name/index and child as argument 
    21092109     * @param fn(index, child) callback function for each child 
    2110      */ 
    2111     AbstractContainerControl.prototype.eachChild = function(fn, stopable) { 
     2110     * @param stopable  boolean specifiying if the first false return will stop processing to other children 
     2111     * @param includeAll boolean indicating if the 'hidden' children of this container should be included (see case-control) 
     2112     */ 
     2113    AbstractContainerControl.prototype.eachChild = function(fn, stopable, includeAll) { 
    21122114        stopable = stopable || false; 
     2115        includeAll = includeAll || false; 
    21132116        if (!$.isFunction(fn)) { 
    21142117            return; 
    21152118        } 
    21162119        //else 
    2117         var children = this.getChildren(); 
     2120        var children = this.getChildren(includeAll); 
    21182121        if (!stopable) { 
    21192122            for (var i in children) { 
     
    23752378     * Gets all child controls 
    23762379     * @return object containing all the children 
     2380     * @param includeAll boolean indicating if the 'hidden' children of this container should be included (see case-control) 
    23772381     * @type Object 
    23782382     */ 
     
    26632667            if (child.delegates) 
    26642668                child.delegate.apply(child, args);  
    2665         }); 
     2669        }, false, true); 
    26662670    } 
    26672671      
  • trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-form.js

    r1863 r1873  
    727727}); 
    728728 
     729 
     730test("delegation of case-control issue #449", function() { 
     731 
     732    // create 
     733    var $main = $('#main').show(); 
     734     
     735    var delegatesExecuted = []; 
     736 
     737    var $form = $('<form></form>').appendTo($main); 
     738    var fconf = { 
     739 
     740        members : { 
     741            'c' : { 
     742              base: 'case', 
     743              "+validators": { "required": {} }, 
     744              "control": { 
     745                  "base": "case-control", 
     746                  "nullable": false, 
     747                  "initial":{"value": {"case":"t"}} 
     748              }, 
     749              "cases": { 
     750                  "t" : { 
     751                      "base": "string", 
     752                      control: 'my-test-control' 
     753                  }, 
     754                  "n" : { 
     755                      "base": "string", 
     756                      control: 'my-test-control' 
     757                  } 
     758              } 
     759            }    
     760        }, 
     761 
     762        controlTypes : { 
     763            'my-test-control' : { 
     764                base :'input-control', 
     765                delegates: true, 
     766                testDelegate: function(x) { 
     767                  delegatesExecuted[delegatesExecuted.length] = this.getId(); 
     768                }, 
     769                initial: {value: "s"} 
     770            } 
     771        } 
     772    }; 
     773 
     774    var form = new $.org.kauriproject.forms.Form($form, fconf); 
     775     
     776    expect(2); 
     777 
     778    form.delegate("testDelegate", "x"); 
     779     
     780    ok($.inArray("case-t", delegatesExecuted) > -1, "checking delegation ran for active case."); 
     781    ok($.inArray("case-n", delegatesExecuted) > -1, "checking delegation ran for non-active case."); 
     782     
     783    // cleanup 
     784    $main.html("").hide(); 
     785        
     786}); 
     787 
     788 
    729789test("inital valid-state of various container controls", function() { 
    730790 
Note: See TracChangeset for help on using the changeset viewer.