So I got asked today for a way to block end users from attaching files to list items on a particular list. So I whipped out jQuery and quickly wrote a little selector to hide that page region. So you can see I just go off of the Attach File image and go up a few levels to get both img and the text label. Then I flag them as hidden.
#1 by Marc D Anderson on March 31, 2011 - 3:59 pm
If you’ve ever heard of me, you’ll know that I am a *huge* jQuery fan. However, this is, to me, an excellent example if a time not to use jQuery. A simple bit of CSS will take care of it and be more reliable.
Understanding when to pull out jQuery and when not to is one of the things I try to teach my students at USPJ Academy (http://uspja.com).
M.
#2 by Maarten on March 31, 2011 - 4:14 pm
Unfortunately with how SharePoint 2007 has the attach item done theres really no good selector for CSS (pre-CSS3) to get just the attach item link and image. Using normal CSS2.x selectors you would end up hiding quite a few page regions.
But you’re absolutely right, if you have your page elements properly segmented and identified CSS is a MUCH better route to go.
#3 by Marc Anderson on April 1, 2011 - 4:26 am
Maarten:
There’s always a way to do the selection in CSS; it just takes practice.
That said, several people have pointed out the more obvious solution on Twitter: simply disable attachments for the list through the UI.
M.
#4 by Nate on July 2, 2013 - 1:28 pm
I had a requirement to allow this on some forms and not on others within the same list. The easiest way I’ve found to do this at the form level is to create a custom form in SP Designer and check the box to disable the standard toolbar. This will make it so the attachment link isn’t visible for that form. No coding required.
#5 by Maarten on July 2, 2013 - 3:29 pm
This was a fringe case where Designer wasn’t an option, and it had existing attachments that needed to continue to be accessed. Only new forms should not be allowed. So jQuery 🙂