Changeset 1874 for trunk


Ignore:
Timestamp:
2011-03-15 10:13:14 (14 months ago)
Author:
mpo
Message:

Simple testcase showing the use of a no-format user-format when needing to select backend option values with explicit spaces.
Point is that kauri-forms will automatically trim all string-input values and thus remove excess spaces which in the select-control leads to mismatches and normalization not finding the actual option-value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-basic-controls.js

    r1868 r1874  
    215215 
    216216 
     217test("trimmed selection-control stringvalues", function() { 
     218     
     219    // create 
     220    var $main = $('#main').show(); 
     221    var $form = $('<form />').appendTo($main); 
     222 
     223    var id = "s0"; 
     224    var options=["none", "one: ", "two:  ", "three:   "]; 
     225    var fconf = { "members": {}}; 
     226    fconf.members[id] = { 
     227        "base": "string", 
     228        "+validators": { 
     229            "isOption": {} 
     230        },  
     231        "user-format": "no-format", 
     232        "control": { 
     233            "base": "selection-control", 
     234            "options": { 
     235                "data": options 
     236            } 
     237        }, 
     238    }; 
     239    fconf.formatters = { 
     240        "no-format": { 
     241            format: function( val)   { return val; }, 
     242            parse : function( valstr){ return valstr; }     
     243        } 
     244    } 
     245 
     246    var form = new $.org.kauriproject.forms.Form($form, fconf); 
     247 
     248    expect(6); 
     249 
     250 
     251    // verify creation of control 
     252    var c = form.findControl(id); 
     253    ok(c != null, "control creation passed"); 
     254    equals(c.getForm(), form, "control form ok"); 
     255    equals(c.getId(), id, "control id checked"); 
     256         
     257    // verify setting some valid value in untrimmed version 
     258    c.setWireValue(options[1]); 
     259    equals(c.getValue(), options[1], "checking that the untrimmed value was selected to second option"); 
     260     
     261    // verify setting untrimmed value via UI 
     262    var $input = $('select[kauri-idref*="'+id+'"]', $form); 
     263    var $options = $("option", $input); 
     264    $options.removeAttr("selected"); 
     265    $options.eq(2).attr("selected","selected"); 
     266    $input.change(); 
     267    equals(c.getValue(), options[2], "checking that the untrimmed value was selected to third option"); 
     268     
     269    // verify setting untrimmed value 
     270    $input.val(options[3]); 
     271    $input.change(); 
     272    equals(c.getValue(), options[3], "checking that the untrimmed value was selected to fourth option"); 
     273     
     274     
     275    // cleanup 
     276    $main.html("").hide(); 
     277     
     278}); 
     279 
    217280test("multivalue selection-control", function() { 
    218281 
Note: See TracChangeset for help on using the changeset viewer.