Disabled Form Elements
November 6th, 2008Most browsers (Firefox, Safari) won't pass disabled form elements during submission. This caused me quite a bit of trouble this morning until I decided to check the development.log for the POST data when editing my model. My solution was two part, first being javascript and second being CSS.
Javascript: enable all elements before submitting
1 2 3 4 5 6 7 8 9 10 11 |
function addFormListener() { $$('form').each(function(f) { f.observe('submit', function(){ f.getInputs().each(function(i){ i.enable(); }); }); }); }; Event.observe(window, 'load', addFormListener()); |
CSS: maintain styles for disabled elements and class=disabled
1 2 3 4 |
input.textField.disabled { background-color: #eee; color: #808080; border: 2px solid #808080; } |
What about read-only or locked attributes?
Those should be handled in your model anyway and blocked from mass-assignment. Remember? skinny controllers, fat models!






Adam Cooke
December 3rd, 2008 at 09:45 PM
sob
December 3rd, 2008 at 11:49 PM