Changeset 1951 for trunk


Ignore:
Timestamp:
2011-09-14 13:11:10 (8 months ago)
Author:
mpo
Message:

Allow for wire-value to contain ".meta" information available at the control-instance level.
This can be used e.g. for sending additional control-conf data (like option lists) that is logically is available together with the values.
Fixes #471.

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

Legend:

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

    r1950 r1951  
    21192119    }; 
    21202120     
     2121    /**  
     2122     * Allows storing arbitrary meta-data 
     2123     */ 
     2124    Control.prototype.setMeta = function(m) { 
     2125        this.meta = m; 
     2126    }; 
     2127    Control.prototype.getMeta = function() { 
     2128        return this.meta; 
     2129    } 
     2130    Control.prototype.addMeta = function(m) { 
     2131        this.meta = this.meta || {}; 
     2132        $.extend(this.meta, m); 
     2133    } 
    21212134     
    21222135     
     
    23622375     */ 
    23632376    AbstractContainerControl.prototype.setWireValue = function(value, noValidation){ 
     2377        var meta = value[".meta"];  
     2378        if ( meta !== undefined && meta !== null) { 
     2379            this.setMeta(meta); 
     2380            delete value[".meta"]; 
     2381        } 
     2382         
    23642383        var w = this.getType().parseWireValue(value); // allow composite-type specific parsing (split)  
    23652384        return this.setLoop(AbstractContainerControl.childWireSetter, w, noValidation); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-form.js

    r1927 r1951  
    874874}); 
    875875 
    876 }); 
     876 
     877test("basic form with meta-data", function() { 
     878 
     879    // create 
     880    var $main = $('#main').show(); 
     881 
     882    var $form = $('<form />').appendTo($main); 
     883    var $fld = $('<input type="text" kauri-idref="fld">').appendTo($form); 
     884 
     885    // test 
     886    expect(4); 
     887 
     888    var fconf = { 
     889        members : { 
     890            "fld" : { 
     891                type :'string' 
     892            } 
     893        } 
     894    }; 
     895     
     896    var form = new $.org.kauriproject.forms.Form($form, fconf); 
     897 
     898    equal(form.isComplete(), true, "checking form.isComplete after initializing..."); 
     899    var fldc = form.findControl("/fld"); 
     900 
     901    form.setWireValue( { 
     902        "fld"   :"data", 
     903        ".meta" :"meta-data" 
     904    }); 
     905 
     906    equal(form.getValue().fld, "data",  "get-set value match of data."); 
     907    equal(form.getMeta(), "meta-data",  "get-set value match of meta-data."); 
     908    ok(form.getValue()[".meta"] == null,"no traces of meta-data in value."); 
     909 
     910    // cleanup 
     911    $main.html("").hide(); 
     912}); 
     913 
     914}); 
Note: See TracChangeset for help on using the changeset viewer.