PDA

View Full Version : Making a combo read-only


PowerMacX
2005.07.04, 09:15 AM
I'm working on a generic, web based (AJAX) form for entering data, but I ran into a problem: By default, I want all fields to be read-only, so the user can browse records without accidentally modifying them. Clicking on a Modify or New button should switch the state of all fields to editable.

So far, normal text fields work just by updating their "readonly" property, but neither combos nor checkboxes seem to respect that setting :mad:. The only way I found to force them to be readonly is by setting their "disabled" property to true, but in many browsers, Firefox for instance, disabled combos have very light gray text, almost unreadable.

Other than "showing" and hiding an invisible layer on top of every combo to prevent clicks, is there an easy way to make this controls read-only?

PowerMacX
2005.07.04, 01:56 PM
To (partially) answer my own post, this is what I manged to get right now:

For the Combo:
onmousedown='if (!gEditing) blur(self);return gEditing;' onclick='if (!gEditing) blur(self);'

For the Checkbox:
onmousedown='if (!gEditing) blur(self);return gEditing;' onclick='return gEditing;'

(gEditing is a global that is true if the field are modifiable.)

This are inline javascript event handlers, as in:
<input type="button" id="something" onclick='javascript stuff'>

This works in Safari, Firefox and Konqueror, but not in IE (as usual...).
Also, in Firefox the combo can be edited if the user simply clicks and holds, instead of simply clicking. And in Konqueror the checkboxes are always editable...

Anyone has any suggestions?

Thanks in advance.

Edit: Actually, it does work on IE Mac :???: but not on IE 6 Windows :mad:

Wevah
2005.07.04, 07:29 PM
I think instead of blur(self) you want this.blur().

PowerMacX
2005.07.05, 10:01 AM
I think instead of blur(self) you want this.blur().

You are right. On the other hand, inline javascript functions seem to default to "this.", and ignore extra parameters, so I guess I could just as well have written "blur(isNotAsGoodAsOasis)" and it would have worked too... :p

Anyway, I replaced it with this.blur() so it makes more sense, but since that didn't change the results, I had to resort to USER_AGENT in PHP and make different "patches" for IE Win & Konqueror. Not the best way to go though. :(