Changeset 1918


Ignore:
Timestamp:
2011-07-26 10:00:28 (10 months ago)
Author:
jgou
Message:
  • improved checking of rows and cols attributes for textarea-control, this fixes #466 (tested in IE8, FX3, FX5, chrome11)
  • add qunit test for textarea-control (including test for #466)
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/basic-controls.js

    r1914 r1918  
    414414        } 
    415415 
    416  
    417             ($textarea.attr('cols') != -1)? (this.cols = $textarea.attr('cols')) : $textarea.attr('cols', this.cols); 
    418             ($textarea.attr('rows') != -1)? (this.rows = $textarea.attr('rows')) : $textarea.attr('rows', this.rows); 
    419             // attr('readonly') always returns a value, even if it's not specifically set 
    420             // the only way to check this, is by using an attribute selector 
    421             ($('textarea[readonly]' ,$('<div />').append($textarea.clone())).size() == 1)? (this.readonly = $textarea.attr('readonly')) : $textarea.attr('readonly', this.readonly);            
     416        var $unselectableElement = $('<div />').append($textarea.clone()); 
     417        // workaround to prevent #466 caused by: attr('cols') and attr('rows') always return a value in most browsers 
     418        // note: in jquery 1.6 this should get easier (see .attr() and .prop() in jquery docs) 
     419        ($('textarea[cols]' ,$unselectableElement).size() == 1)? (this.cols = $textarea.attr('cols')) : $textarea.attr('cols', this.cols); 
     420        ($('textarea[rows]' ,$unselectableElement).size() == 1)? (this.rows = $textarea.attr('rows')) : $textarea.attr('rows', this.rows); 
     421        // attr('readonly') always returns a value, even if it's not specifically set 
     422        // the only way to check this, is by using an attribute selector 
     423        ($('textarea[readonly]' ,$unselectableElement).size() == 1)? (this.readonly = $textarea.attr('readonly')) : $textarea.attr('readonly', this.readonly);            
    422424    } 
    423425     
  • trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-basic-controls.js

    r1914 r1918  
    220220 
    221221 
     222test("textarea-control", function() { 
     223 
     224    // create 
     225    var $main = $('#main').show(); 
     226    var $form = $('<form />').appendTo($main); 
     227 
     228    var okValue = "test"; 
     229    var nokValue = "n*" + okValue; 
     230    var mockSet = makeMockValidator(okValue); 
     231    var mockVal = mockSet[0]; 
     232    var mockMsg = mockSet[1]; 
     233    var cols = 80; 
     234    var rows = 10; 
     235    var readonly = true; 
     236 
     237    var id = "t0"; 
     238    var fconf = { "members": {}}; 
     239    fconf.members[id] = { 
     240        "base": "string", 
     241        "control": { 
     242            "base": "textarea-control", 
     243            "cols": cols, 
     244            "rows": rows, 
     245            "readonly": readonly 
     246        }, 
     247        "validators": [mockVal] 
     248    }; 
     249 
     250    var form = new $.org.kauriproject.forms.Form($form, fconf); 
     251 
     252     
     253    expect(15); 
     254 
     255    // verify creation of control 
     256    var c = form.findControl(id); 
     257    ok(c != null, "control creation passed"); 
     258    ok(c.getForm() == form, "control form ok"); 
     259    equal(c.getId(), id, "control id checked"); 
     260 
     261    // verify creation  of control elements 
     262    var $textarea = $('textarea[kauri-idref*="'+id+'"]', $form); 
     263    var $messages = $("span[kauri-idref*='"+id+"']", $form); 
     264    $messages.html("text that should get cleared upon validation"); 
     265    sameJq(c.getElement(), $textarea, "textarea element found and indexed."); 
     266    sameJq(c.getElement('messages'), $messages, "messages element found and indexed.")   
     267     
     268    // verify setting some value 
     269    c.setWireValue(okValue); 
     270 
     271    equal($messages.html(), "", "validation error clearing."); 
     272    equal(c.getValue(), okValue, "get-set value match."); 
     273 
     274     
     275    // verify events 
     276    var changes = 0; 
     277    c.valueChanged( function() { 
     278        changes++ 
     279    }); 
     280 
     281    // mock user interaction: set other value on checkbox & trigger change 
     282    $textarea.val(nokValue).change(); 
     283 
     284    equal(changes, 1, "receiving value-change event"); 
     285    equal(c.hasChanges(), true, "change state") 
     286    equal($messages.html(), mockMsg, "validation error setting."); 
     287    equal(c.getValue(), nokValue, "get-set value match."); 
     288 
     289    // mock user interaction: blur without change 
     290    c.getElement("input").blur(); 
     291 
     292    equal(changes, 1, "checking possible duplicate value-change event"); 
     293     
     294    // #466 : check if rows and cols properties are set correctly 
     295    equal($textarea.attr("cols"),cols,"check cols value"); 
     296    equal($textarea.attr("rows"),rows,"check rows value"); 
     297    equal($textarea.attr("readonly"),readonly,"check readonly value") 
     298 
     299    // cleanup 
     300    $main.html("").hide(); 
     301}); 
     302 
     303 
    222304test("trimmed selection-control stringvalues", function() { 
    223305     
Note: See TracChangeset for help on using the changeset viewer.