Changeset 1924


Ignore:
Timestamp:
2011-08-04 13:52:13 (10 months ago)
Author:
sdm
Message:

radioselection.js: changed the "input[checked]" selector to "input[type='radio']:checked" (fixes #468)
radioselection.js: use options.trimValues instead of this.trimToOptions
Also added test cases for radioselection-control and selection-control (set-get value tests still fail!)

Location:
trunk/modules/kauri-forms
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-forms/kauri-forms-extra/src/main/kauri/static/radioselection/js/radioselection.js

    r1920 r1924  
    112112        var $radioControlDiv = this.getElement(); 
    113113         
    114         var $checkedRadioButton = $radioControlDiv.find("input[checked]"); 
     114        var $checkedRadioButton = $radioControlDiv.find("input[type='radio']:checked"); //input[checked] 
    115115        return $checkedRadioButton.val(); 
    116116    } 
     
    134134        
    135135       // clear options from list that are not available 
    136        value = trimToOptions(value, values); 
     136       value = this.options.trimValues(value); 
    137137        
    138138       if (value === undefined  // if no matches left after trim  
     
    144144       return value; 
    145145   } 
    146      
    147    function trimToOptions(val, values) { 
    148        
    149       if (val === undefined || values === undefined) return undefined; 
    150       if (val.constructor != Array) { 
    151           var wrapped = trimToOptions([val], values); //wrap 
    152           return (wrapped != undefined) ? wrapped[0] : undefined; // unwrapped 
    153       } 
    154        
    155       var result = [];  
    156       for (var i = 0; i< val.length; i++) { 
    157           var testval = val[i]; 
    158           if ($.valueInArray(testval, values) >= 0) { 
    159               result[result.length] = testval; 
    160           } 
    161       } 
    162       return (result.length == 0 ) ? undefined : result; 
    163   } 
    164146     
    165147 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-basic-controls.js

    r1918 r1924  
    301301}); 
    302302 
     303test("selection-control", function() { 
     304 
     305    // create 
     306    var $main = $('#main').show(); 
     307    var $form = $('<form />').appendTo($main); 
     308 
     309    var id = "selection1"; 
     310    var fconf = { "members": {}}; 
     311    fconf.members[id] = { 
     312        "base": "string", 
     313        "label": "Number select", 
     314        "control": { 
     315            "base": "selection-control", 
     316            "options": { 
     317                  "data": [{name:"one",id:1}, {name:"two",id:2}, {name:"three",id:3}], 
     318                  "valueTemplate": "{id}", 
     319                  "labelTemplate": "{name}" 
     320            } 
     321        } 
     322    }; 
     323 
     324    var form = new $.org.kauriproject.forms.Form($form, fconf); 
     325     
     326 
     327    expect(8); 
     328     
     329     
     330    // verify creation of control 
     331    var c = form.findControl(id); 
     332    ok(c != null, "control creation passed"); 
     333    ok(c.getForm() == form, "control form ok"); 
     334    equal(c.getId(), id, "control id checked"); 
     335     
     336    // verify creation  of control elements 
     337    var $input = $('select[kauri-idref*="'+id+'"]', $form); 
     338    var $messages = $("span[kauri-idref*='"+id+"']", $form); 
     339    $messages.html("text that should get cleared upon validation"); 
     340    sameJq(c.getElement(), $input, "input element found and indexed."); 
     341    sameJq(c.getElement('messages'), $messages, "messages element found and indexed.")   
     342     
     343    equal(c.getValue(), 1, "initial value should be the first"); 
     344     
     345    // verify setting some value 
     346    c.setValue(3); 
     347    equal(c.getValue(), 3, "setValue should trigger a change of value"); 
     348     
     349    c.setWireValue(2); 
     350    equal(c.getValue(), 2, "setWireValue should trigger a change of value"); 
     351     
     352    // cleanup 
     353    $main.html("").hide(); 
     354     
     355}); 
     356 
    303357 
    304358test("trimmed selection-control stringvalues", function() { 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/testPage.html

    r1899 r1924  
    4747  <script type="text/javascript" src="../../main/kauri/static-{build}.key/kauri.forms/date.js" ></script> 
    4848  <script type="text/javascript" src="../../main/kauri/static-{build}.key/kauri.forms/numeric-range.js" ></script> 
     49  <script type="text/javascript" src="../../../../kauri-forms-extra/src/main/kauri/static/radioselection/js/radioselection.js" ></script> 
    4950  <!-- 
    5051  <script type="text/javascript" src="../../main/kauri/static/js/location.js" ></script> 
     
    8687  <script type="text/javascript" src="test-date.js" ></script> 
    8788  <script type="text/javascript" src="test-numeric-range.js" ></script> 
     89  <script type="text/javascript" src="test-radioselection.js" ></script> 
    8890    
    8991  <!-- Haven't found a way to test the control since the page has to be completly loaded to be able to load the maps api 
Note: See TracChangeset for help on using the changeset viewer.