views:

225

answers:

2

I have a web application with a form that has disabled fields in it. It allows a "Save As" function which basically means the settings can be copied into a new configuration (without being modified) and in the new configuration they can be changed to something else. The problem I am running into with this is that since the fields are disabled, they are not getting posted through and do not appear in the context object on the server side.

When I removed the logic to disable the fields, that part works fine. So the remaining problem is, how to "disable" the fields (not allow any change of the data in any of the entry fields) without really "disabling" them (so that the data gets posted through when saving)?

I was originally looking for a way to do this in CSS but not sure if it exists. The best solution is of course, the simplest one. Thanks in advance!

(Note: by 'disabled' I mean "The textboxes display but none of the text inside of them can be modified at all". It does not matter to me whether the cursor appears when you click inside it, though if I had a preference it would be no cursor...)

+2  A: 

http://www.w3schools.com/TAGS/att_input_readonly.asp readonly attribute is what you want.

No Refunds No Returns
perfect... it was staring me right in the face :) I just loop through the elements that were previously being disabled and instead add the attr readonly and it works. in Jquery it looks like: //disable($(this)); (OLD) $(this).attr("readonly", "readonly"); (NEW)
n2009
gotta love the simple ones
No Refunds No Returns
@n2009 - so it's ok for someone using a screen reader that doesn't support JS to change those fields. I hope you're also doing some server-side validation to make sure they have been changed.
tvanfosson
how about adding a onclick or ontextchanged event to the textbox to nullify any attempts in updating the text ...
aggietech
+1  A: 

i would suggest that instead of using the non-updateable field values from the page's inputs, you retrieve the original object from the DB and copy them from there. It's pretty trivial using something like Firebug to modify the contents of the page whose form will be posted back to modify the values, even if they are marked as readonly. Since you really want the values from the original, I would simply reget the object and copy them. Then you don't need to worry about whether the original (and non-updateable) properties get posted back at all.

tvanfosson
You don't even need Firebug. This can be done from any standard browser address bar.
Josh Stodola
I was just giving one trivial way to do it, not enumerating all of the trivial ways.
tvanfosson