Page 1 of 1

Turn off "Other..." on select / checkboxes

PostPosted: Tue Jul 19, 2011 10:27 am
by jimr451
Hi,

I have some "transient" fields and normal select box relationships set up. But each one on the "edit" screen shows the options, then an "Other..." link which allows you to add another option on the fly. I'd like have those tables edited elsewhere, if at all, and just turn off the "Other..." link.

I looked around, but can't figure out how to do that.

Any ideas?

-Jim

Re: Turn off "Other..." on select / checkboxes

PostPosted: Tue Jul 19, 2011 10:36 am
by shannah
That option is subject to the 'add new related record' permission, so you can disable it by denying the use the 'add new related record' permission for that relationship. Of course that would also prevent the same user from adding new related records to that relationship in other parts of the interface also.

You could also use CSS to just hide this link if you don't intend to disable the action entirely for the user but just want to hide it from the interface. Use permissions to solve permission related problems and CSS/preferences to solve UI related problems, and try hard to understand whether a problem is related to UI or permissions before making a choice.

-Steve

Re: Turn off "Other..." on select / checkboxes

PostPosted: Tue Jul 19, 2011 11:32 am
by jimr451
Thanks - that pointed me in the right direction. I added a function in my [tablename].php file:


Code: Select all
function rel_atmospheres__permissions(&$record) {
  return array(
            'add new related record' => 0
            );
}


(the relationship was named 'atmospheres' - this seemed to do the trick, and I think the "admin" can still edit the atmospheres table directly to add choices.)

Thanks,

-Jim

Re: Turn off "Other..." on select / checkboxes

PostPosted: Tue Jul 19, 2011 11:39 am
by shannah
That's the right idea. Generally in my applications I try to give my admin user full access - and limit access to other users. Assuming you have defined a function called isAdmin() that returns true if the currently logged in user is an admin user, you could alter the code as follows to make admins exempt from these permission limitations:
Code: Select all
function rel_atmospheres__permissions(&$record) {
    if ( isAdmin() ) return null;
    return array(
            'add new related record' => 0
            );
}


Best practice is to actually deny all access to users at the global level (except admins), and then add access at the table, field, and relationship levels explicitly to other users as required. That minimizes the chances of accidentally giving users access to things they shouldn't have access to.

-Steve