Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6887: non-form-disable.diff

File non-form-disable.diff, 1.8 kB (added by mislav, 2 years ago)

here you go + unit tests with fieldset ;)

  • src/form.js

    old new  
    5656 
    5757  disable: function(form) { 
    5858    form = $(form); 
    59     form.getElements().each(function(element) { 
    60       element.blur(); 
    61       element.disabled = 'true'; 
    62     }); 
     59    Form.getElements(form).invoke('disable'); 
    6360    return form; 
    6461  }, 
    6562 
    6663  enable: function(form) { 
    6764    form = $(form); 
    68     form.getElements().each(function(element) { 
    69       element.disabled = ''; 
    70     }); 
     65    Form.getElements(form).invoke('enable'); 
    7166    return form; 
    7267  }, 
    7368 
  • test/unit/form.html

    old new  
    176176      }); 
    177177    }}, 
    178178     
     179    testFormEnabling: function(){ with(this) { 
     180      var form = $('form_focus') 
     181      var input1 = form.focus_disabled 
     182      var input2 = form.focus_text 
     183       
     184      assert(input1.disabled) 
     185      assert(!input2.disabled) 
     186       
     187      form.disable() 
     188      assert(input1.disabled) 
     189      assert(input2.disabled) 
     190       
     191      form.enable() 
     192      assert(!input1.disabled) 
     193      assert(!input2.disabled) 
     194       
     195      input1.disable() 
     196      assert(input1.disabled) 
     197       
     198      // non-form elements: 
     199      var fieldset = $('form_fieldset') 
     200      var fields = fieldset.immediateDescendants() 
     201      assert(fields.all(function(select){ return !select.disabled })) 
     202       
     203      Form.disable(fieldset) 
     204      assert(fields.all(function(select){ return select.disabled })) 
     205       
     206      Form.enable(fieldset) 
     207      assert(fields.all(function(select){ return !select.disabled })) 
     208    }}, 
     209     
    179210    testFormElementEnabling: function(){ with(this) { 
    180211      assert($('input_disabled').disabled); 
    181212      $('input_disabled').enable();