First, the generic CSS and JavaScript part. In my test case I put the following code in the page header. If something like this goes production, it should be in separate files, of course:
<style type="text/css">
.js_checkbox { display:none; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript">
function set_yn(i_checkbox,i_apex_field_id) {
document.getElementById(i_apex_field_id).value =
(i_checkbox.checked? "Y" : "N");
}
$().ready(function() {
$(".js_checkbox").each(function() {
$(this).after("<input id='"+this.id+"_js' type='checkbox' "+
(this.value==="Y" ? "checked='checked' " : "") +
"onchange='javascript:set_yn(this,"+'"'+this.id+'"'+")'/>");
});
});
</script>
Second, the column definition:
* Display As: Text Field (the default)
* Element Attributes: class="js_checkbox"
Please note that this code is just a quick hack in response to Patrick's topic, not thoroughly tested etc.
2 comments:
hi ,
great post ... thanxs for posting this .... ;)
Hello,
I have to confirm, its very nice and sexy cript :)
But I'm experiencing one issue.
When using that when I'm creating new record, I leave it unchecked and the field in DB cannot be null, then it fails, becouse it tries to fill this field with null value ...
Any advice?
(I know, there is workaround - use trigger to fill it with any default value, but it's not so 'sexy' as it was before :D )
with kind regards
Vitek
Post a Comment