last updated 10/7/2019
This one has been on my list for a while. I’ve used a collection of JavaScript methods to help streamline customizing forms in lists. I have created and compiled this little collection starting probably 5-6 years ago, and over time I’m constantly updating, tweaking, enhancing it, especially more so as of late working with Office 365.
This script works on SharePoint 2013, 2016 and Online. I heard it works on 2010 as well, though I haven’t had much experience with it there. Let me know!
I have a lightweight JavaScript file which allows you to hide or disable (set to read-only) fields in a new or edit form. It’s pretty basic but is a big value add. Also, you can set a field to read-only for only certain groups, meanwhile allowing other groups to edit the field. You can also hide a field completely, as well as hide a field and only show it for certain groups. Pretty sweet right?
This script now includes some basic formatting options! Check out more detail here.
The script is here: download from GitHub.
How to use it
Include the script along with jQuery on your page. Ideally, throw this nugget into your master page and you can use it anywhere in your site.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="path/to/file/Lozzi.Fields.js"></script>Once that’s in, get using it! It’s really simple, I threw this on my new form for my task list:
$(document).ready(function(){ ExecuteOrDelayUntilScriptLoaded(function(){ Lozzi.Fields.disableWithAllowance("Start Date", ["Project Managers"]); Lozzi.Fields.disable("Task Status"); Lozzi.Fields.hide("% Complete"); },"sp.js"); });This will change our New form for a typical task, from:
to
See the difference? It’s subtle, but when working with end users, it can provide a huge benefit to help streamlining your business flow.
From here, you could have the edit form disable or hide a lot of the fields for normal users, only allowing your Project Managers, or if this is a support request list, your Support Team access to modify fields as needed. The options are endless.
More details
Lozzi.Fields.disable(fieldname)
Simply disables the field, for all users. It hides all controls in the field and displays the value instead.
Lozzi.Fields.disableWithAllowance(fieldname, groups)
Disables the field, but enables it for the users in the groups specified. Also, Site Collection Administrators are included automatically, so they can always edit the field. You can send the groups in an array, like [“Group One”, “Group Two”].
Lozzi.Fields.hide(fieldname)
Simply hides the field, for all users.
Lozzi.Fields.hideWithAllowance(fieldname, groups)
Hides the field, but shows it for the users in the groups specified. Also, Site Collection Administrators are included automatically, so they can always edit the field. You can send the groups in an array, like [“Group One”, “Group Two”].
Some other important notes
- Currently, this script does not work on list views, meaning a user could edit the data in datasheet/quick edit view.
- This script should work just as well on SharePoint 2010 if you so desire.
Download this script here: download from GitHub.
Til next time, Happy SharePointing!
Hi David
Love the script, really useful. Having a small problem though.
I am using o365 and when I try to disable a ‘Multi Line Text’ field it, disables it and then just shows text, but then directly below it shows the text box.
Any Idea what is going on here?
Gary
LikeLike
Hi David
Further 2 my query above, this only happens for ‘Multiple line of text’ fields when they are ‘Rich text’ or ‘Enhanced rich text’ it does not happen for types of ‘Plain text’
Thanks
Gary
LikeLike
Thanks for the feedback. I’ll check it out.
LikeLike
Fixed! Grab the latest from https://lozzisp2013.codeplex.com/
LikeLike
Thanks David
LikeLike
Hi David have you manage to get around that as i am getting the same as Gary?
LikeLike
Fixed! Grab the latest from https://lozzisp2013.codeplex.com/
LikeLike
Hi, I am new to SP. We are running hosted Office 365. I saved the .js file in Site Assets and put the script into my page but it’s not making any difference. It didn’t work for me but that may be because I am a Site Collection Admin but I’ve also checked with a user who is a normal user. I’ve tried DisableWithAllowance and Disable. Any ideas?
LikeLike
Did you add jQuery to your page as well? Are you getting an script errors, see https://davidlozzi.com/2013/05/15/a-non-developers-intro-to-the-developer-toolbar-scripting/ for help there.
LikeLike
Update: In addition to this not working, it removed the links at the top of the page for editing that page – the tabs for “Items” and “List”.
LikeLike
Did you see my previous reply? Do you have jQuery? Are you seeing any script errors?
Those tabs sound like tabs for a list view, and this script should be on a form for a list item, so those tabs shouldn’t exist at all.
LikeLike
I. I followed your instructions and it seems that I have Jquery installed. I am getting erros though – SCRIPT 70: Permission Denied. I will email you a screen shot.
LikeLike
Hi David. I try to use your library and a have a strange problem (I am not familiar with jQuery and Javascript): In EditForm.aspx of a list i have used a script editor in which I have used the exact code:
$(document).ready(function(){
Lozzi.Fields.hide(“MyField”);
});
With the help of development tools of my browser i see that my page ‘views’ your library but it never runs the above script code. When though i run on debug console the whole script or just the command Lozzi.Fields.hide(“MyField”);… it works! Can you understand which is the problem?
Thanks in advance!
LikeLike
it worked! Don’ t be bother to deal with it. I dont know what was wrong! Thanks for your time! Please delete my post…
LikeLike
Hi David, disableWithAllowance and hideWithAllowance doesnt work for me. i set up a group called developers on my site and have this code Lozzi.Fields.disableWithAllowance(“Assigned To”, [“Developers”]); however the field is disabled for everyone including me and i am in the developer group. any idea what im doing wrong?
LikeLike
Hi Sonia,
That looks right, so I’m wondering if there’s an error in the script. Can you run your developer toolbar, see https://davidlozzi.com/2013/05/15/a-non-developers-intro-to-the-developer-toolbar-scripting/, and see if any errors are occurring?
Thanks,
David
LikeLike
Hi David, I checked and there are no issues – i copied a sample of my script – maybe you will be able to see what’s wrong from this code
removed code to save space on blog, please email it to david.lozzi at slalom.com
LikeLike
I’m not sure this is the right code, I see more SharePoint code than my utils in here. Can you email me the code at david.lozzi at slalom.com? Thanks!
LikeLike
It worked :) thank you for this amazing script and for your time helping me to troubeshoot my jquery issues
LikeLike
Hi, I have been having the exact same issue that sonia had with the disableWithAllowance function, the field is disabled for everyone include site collection admins. I tried adding extra alerts into the code and they are not being triggered in either the getGroupsAndEnable or asyncFailed functions, that makes me think it is something to do with the spContext not being set.
If you have any ideas if would be great, this code looks very useful.
Thanks
Henry
LikeLike
Can you confirm jQuery is loading properly? We were having an issue with that for a little bit.
LikeLike
Any luck?
LikeLike
Try this new script if you will, https://lozzisp2013.codeplex.com/releases/view/127625, I removed the condition for site collection administrators.
LikeLike
Hi David, I am also having the same issue mentioned by Sonia & Henry…The field is disabled for every group even I mentioned to allow for “Managers” group. Please help
LikeLike
Hi Sonia, how are you?
I’m having the same problem as you wirh disablewithallowance. Can you tell me, how did you solve this problem?
LikeLike
Hi Leticia, I’ll be working on an update this morning and sending it out to you shortly. Thanks!
LikeLike
Here we go! Give this test script a whirl, let me know how it goes and I’ll update the codeplex: https://www.sugarsync.com/pf/D6239992_94044224_615837
LikeLike
Hi David, just one question, how can I hide some lists using powershell scripts?
LikeLike
Hi David,
I have downloaded your script. But doesnot work with the lookup column.
It hides the label but the drop down is still visible.
Any idea on this one? How to hide the lookup column.
Thanks & regards,
Manish
LikeLike
Can you provide the line of code you’re using?
LikeLike
What version of IE are you running under? I think I found something that might cause an issue.
LikeLike
Hi David,
I have downloaded and used your script from codeplex. Its great and it works perfectly ok for the simple “hide” and “disable” commands but fails when i try to use the “disableWithAllowance” and “hideWithAllowance”.
I’ve performed the following steps with no luck.
1. Created a simple named SP group called “DummyTEST” and added the test account to it.
2. Added the code to a custom list form (edit form type)
Code:
Lozzi.Fields.disableWithAllowance(“Start Date”, [“DummyTEST”]);
3. The “disableWithAllowance” and “hideWithAllowance” doesn’t work and it either disables or hides for everyone. Problem is similar to what was described by Sonia last month. I’m using “jquery-1.11.1.min.js” version of the jQuery file.
I’ve also checked the error logs using the browser developer tools and it only throws warning message related to some body tags. Nothing that I could see related to this code.
Any idea if i’m doing wrong?
Thanks
Sid
LikeLike
Hi Sid,
A couple of others have reported issues with the Allowance functions. I’ve retested and unfortunately continues to work fine here. If you’d like, we can connect remotely and I can see it in action on your computer. Email me, david.lozzi at slalom.com and we can coordinate.
Thanks!
David
LikeLike
I just found a bug that might affect older browsers, please try the latest script from codeplex and let me know
LikeLike
Great post and perfect solution for my need but Weirdly it doesn’t work for me. SP 2013 Onpremise. Included the Jquery locan and Lozzi JS along with the small code in CEWP on all three forms but it doesnt work. Not even hiding or disabling. Any idea of the mistake i’m doing? I can send you the code if you wanna have a look.
LikeLike
Are you getting any errors in the dev toolbar, see https://davidlozzi.com/2013/05/15/a-non-developers-intro-to-the-developer-toolbar-scripting/. If not, send me your scripts, and the HTML output from the page (right click and select View Source).
LikeLike
I just found a bug that might affect older browsers, please try the latest script from codeplex and let me know
LikeLike
Still no luck. Maybe I’m missing something basic
LikeLike
were you able to see if any errors were occurring, using my previously posted link?
LikeLike
Nothing in the developer tools either. I couldnt find any errors with the script
LikeLike
Hi Pavan,
Try this new script if you will, https://lozzisp2013.codeplex.com/releases/view/127625, I removed the condition for site collection administrators.
LikeLike
So, this sounds really interesting but I’m new to this level of customization and don’t really know where to put this on the page. I can’t stick it in the middle of the XSL in SPD (tried that) so I added a script editor web part on the new editform.aspx page and downloaded the .js file to the root site (also copied the js URL and pasted that into the snippet). Any other helpful links or tips to get me going? Thanks!
LikeLike
You’ll also need to include a reference to jQuery, can confirm that’s there?
LikeLike
I did add both snippets into one script editor web part. Looks like this:
$(document).ready(function(){
Lozzi.Fields.disableWithAllowance("Task Name", ["Project Owners"]);
Lozzi.Fields.disable("Start Date");
Lozzi.Fields.disable("Due Date");
});
LikeLike
Try without the disableWithAllowance, others have been reporting that’s causing issues, but I can’t seem to get a legit error from it.
LikeLike
Still no joy, but I think I’m missing something fundamental that is shorthand for the pros. I went to my new form (progressEditForm.aspx) in SPD13, added a web part, and then went to the form in IE and edited the page. Created the script editor, added the snippets, tweaked the fields and URL, downloaded the js file from codeplex, uploaded it to root collection site assets, pasted the js URL into the snippet, verified jquery 1.9.1 is running in our environment. Am I missing anything?
LikeLike
Check if there are any errors being reported: https://davidlozzi.com/2013/05/15/a-non-developers-intro-to-the-developer-toolbar-scripting/
LikeLike
I’m having trouble with DisablewithAllowance part. The following script error appears:
“Unable to get property ‘get_current’ of undefined or null reference”
Any ideas on what might cause this?
If I could get this working om my Office 365 Site, that would be great!
LikeLike
The undefined error has been solved(see code below), but now I’m facing the problem that the disableWithAllowance and hideWithAllowance are not working. There are no erros visible when debugging. Anyone who got these two working in Office 365?
the normal hide and disable funtion works fine.
$(document).ready(function(){
SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, sharePointReady);
});
function sharePointReady() {
Lozzi.Fields.disableWithAllowance(“field1”, [“TESTGROUP”]);
Lozzi.Fields.hideWithAllowance(“field2”, [“TESTGROUP”]);
Lozzi.Fields.disable(“field3”);
}
LikeLike
Hi Remy,
I got this to work on two of my o365 sites, however I’m noticing a trend. Any chance we could connect via Skype/Hangout and I could take a look at your screen and troubleshoot? Let me know via email, david.lozzi at slalom.com
Thanks!
David
LikeLike
Try this new script if you will, https://lozzisp2013.codeplex.com/releases/view/127625, I removed the condition for site collection administrators.
LikeLike
David, I am also trying out this script and I am having problems with the disableWithAllowance and hideWithAllowance functions.
LikeLike
Grate, very good job Lozzi!! wish you all the best.
LikeLike
This is awesome. Thanks, David. I am going to especially like the the disable feature.
One issue I ran into when testing this and can’t solve this is- when I have a column with parentheses it does’t seem to take any action on the field. Say I have “field (test) name” as my column name I have tried:
1) Lozzi.Fields.hide(“field (test) name”);
2) Lozzi.Fields.hide(“field_x0020__x0028_test_x0029__x0020_name”);
What am I missing?
Thanks
LikeLike
nvm, after searching and researching I found out that I have to use escape characters for that like this
Lozzi.Fields.hide(“field //(test)// name”);
worked like a charm. Thanks again for the wonder script!
LikeLike
Good find, thanks for sharing!
LikeLike
nice one, I have an issue in office 365 sharepoint online people picker, It is not displaying just user name, It is displaying all details as shown blow. any way we can display only name in office 365?
10;#sandesh m m,#i:0#.f|membership|sandeshmm@xchanging100.onmicrosoft.com,#sandeshmm@xchanging100.onmicrosoft.com,#sandeshmm@xchanging100.onmicrosoft.com,#sandesh m m,#https://xchanging100-my.sharepoint.com:443/User%20Photos/Profile%20Pictures/sandeshmm_xchanging100_onmicrosoft_com_
LikeLike
Here we go! Give this test script a whirl, let me know how it goes and I’ll update the codeplex: https://www.sugarsync.com/pf/D6239992_94044224_615837
LikeLike
I have also got the same issue that Lozzi.Fields.disableWithAllowance is not working properly. The field gets disabled for everyone. I noticed that few users had the same issue and they have found the solution; I would request those users to write details that how it had resolved.
LikeLike
Hi David,
I tried the script and it’s working fine. But Lozzi.Fields.disableWithAllowance(fieldname, groups) is not working for “People Picker” and “Date” field.
Can you pl look into it.
LikeLike
Here we go! Give this test script a whirl, should fix the People picker field issue, and dates as well. Let me know how it goes and I’ll update the codeplex: https://www.sugarsync.com/pf/D6239992_94044224_615837
LikeLike
I am having issues with People Picker and the drop down fields as well. But the link you provided doesn’t seem to exist. Would you be able to send? I know I am late to the party. Will appreciate the help.
LikeLike
BTW, I was able to fix the PeoplePicker issue. I had to go to the Loozi.js and change ms-inputBox to ms-inputuserfield. That did the trick. Now if only drop down field can be fixed. Ah!
LikeLike
Thanks for the comments. I’m not sure what the issue is exactly :P. I just updated the script for a fix for People Picker and Metadata fields. Can you try this most recent version, also noting the update above to my sample script which includes waiting for sp.js.
LikeLike
the same, Lozzi.Fields.disableWithAllowance(fieldname, groups) is not working for dropdown fields
LikeLike
Can you confirm the type of field you’re using? Is it a lookup? How many items are in the pick list? Dropdowns are working fine from my end. Feel free to email me david.lozzi at slalom.com
LikeLike
Hi David,
I would like to know is this script works fine for any jquery version, or do I have to download the exactly same version that you are using?
Sorry,
I am new working with Jquery, this is my first time
LikeLike
I believe this should work on 1.8 or newer. Give it a try and see what happens ;)
LikeLike
Hi David. Thanks for your information. This solution works for SharePoint cloud? Using Office 365?
LikeLike
Yes! I do most of my dev on Office 365, it will definitely work.
LikeLike
Thanks Again for your answer David =)
I have another doubt… I already add the Jquery to Seattle master page… is this correct?
And which section of my script do I have to insert the lozzy script? Sorry… I am new in this cenario… before I used to work with WebServices in Infopath.. to disable field… which is very simple..
I appreciate your help :)
LikeLike
look at the error I got
Failed to load resource: the server responded with a status of 404 (NOT FOUND)
New%20form%20v2.aspx:512 Uncaught ReferenceError: Lozzi is not defined
$
jquery.min.js:2 function (a,b){return new o.fn.init(a,b)}
LikeLike
Hello David … It’s Works fine now… Finnaly I got :0
But as another users said, I am also having problems witht Lozzi.Fields.disableWithAllowance is not working properly. The field gets disabled for everyone.
Do you have any idea ou new update for this?
Thanks again for your support.
LikeLike
Obs: I’v already downloaded the new version of script (Lozzi Field No Site Col), and stil got the same issue… I’m site collection admin, and the field still disable for me.
David, can you help me on this?
LikeLike
Hi David.. it’s working now… thanks so much for your help.
LikeLike
Excellent! Thanks for the feedback!
LikeLike
How did you get that error to leave?
LikeLike
Hi David,
I’m trying to disable the choice field(radio button) but it’s not working properly. it will disable the field but will add extra text of “ctl100” before the Options. Please tell me how to deal with this.
I have also got the same issue that Lozzi.Fields.disableWithAllowance is not working properly. The field gets disabled for everyone. I’m using latest Lozzifield.js
LikeLike
Hi,
Can you give this version a try? https://www.sugarsync.com/pf/D6239992_94044224_615837. I believe this should do it. I was seeing it not work, but I wasn’t seeing a ctl100. If you continue to have an issue, email me a screen shot, david.lozzi at slalom.com. Thanks!
LikeLike
Hi David,
The link provided above is broke and it says the file is not available for download. Could you please provide an alternative link or email the file to suhas.bobby@gmail.com
LikeLike
Which link? the CodePlex link? It’s working for me here. I’ll email you the file shortly.
LikeLike
David,
I have your most recent code and am using it in a New Item page on office 365 version of sharepoint. But inspite of me being a site collection admin, still the people pickers are disabled for me on the form. Could you please help me on this.
Thanks
Suhas
LikeLike
I have a custom list that contains a date time field. The client requested we trim the time portion of the field to only show two available appointment times of 8:30 am and 1:30 pm. In order to do this I added the following javascript code to the New and Edit forms of the list. The problem I am having is when the users open the edit form it does not maintain the previously selected time value. It shows the first available value of 8:30 AM, so if the users open the edit form and change some other field than the time field they inadvertently change the originally selected time field to 8:30 am even if the originally selected time was 1:30PM. How can I get the code to default to the originally selected time value from the New form within Edit form?
$(document).ready(function () {
var str=[‘8 AM’,’1 PM’];
$(“select[id$=’_DateTimeField_DateTimeFieldDateHours’]”).each(function(i){
$(this).html(“”);
for(var i=0;str[i]!=null;i++){
$(this).append(”+str[i]+”);
}
});
});
$(document).ready(function () {
var str=[’30’];
$(“select[id$=’_DateTimeField_DateTimeFieldDateMinutes’]”).each(function(i){
$(this).html(“”);
for(var i=0;str[i]!=null;i++){
$(this).append(”+str[i]+”);
}
});
});
LikeLike
Hi David,
Thank you for your code.
I dowloaded the last version of Codeplex and also the last version of jQuery. I am using SharePont 2013. The hide and disable arre working properly, however the disableWithAllowance is disabeling for everybody. Can you help please?
Thank you
LikeLike
Nice code.
I have a checkbox. Once it is checked, it should be disabled in editform.
Something like IF checkbox=true Lozzi.Fields.disable(“checkbox”)
Is this easy to do? Can you help me with sample code?
LikeLike
Hello David, Thank you for an awesome script and the continued support with it. I have an issue that nobody has submitted yet. I’m using the script to hide with allowance for 8 columns. I’ve added it to the View, Edit, and New item pages. In IE, it works perfectly for all 3 pages. In Chrome and Firefox, it works for Edit and New, but only hides the first column (in the script) on the View pages. Any ideas?
LikeLike
Update: Using the console, I’m seeing the error, “TypeError: SP.ClientContext is undefined” Line 118 of Lozzi.Fields.Js.
That ONLY happens on the View Item page.
I’ll keep digging and let you know if I can get past it.
LikeLike
Hi David,
Thanks for the great script as with an O365 environment I was unable to modify the field behavior without using VS code.
I did face some issues with integrating the script into my code.
ISSUE 1: disableWithAllowance() and hideWithAllowance() were not working as expected. Some troubleshooting helped me determine that it was occurring due to SP.js not loading as expected. Comments here later validated my issue and it is now RESOLVED. Many thanks.
ISSUE 2: A wait image is shown on the person or group field after disabling it using disableWithAllowance(). It works fine with using just disable().
I can’t attach a screenshot here but will try and find your email and send them to you.
Thanks for your help.
LikeLike
Hi cjojucool,
Could you please let me know how could you make disableWithAllowance() and hideWithAllowance() work on people picker fields. The script is disabling for everybody even if you are a site collection admin. let me know if you can shed some light on this issue.
Thanks
Suhas
LikeLike
Thanks for the feedback. For ISSUE 1 I updated my sample code to wait for sp.js, is this the same method you used?
For ISSUE 2, updated the code. Please grab latest and let me know!
LikeLike
Hi David:
Thank you for the script. Like other people mentioned hide and disable seem to be working great but disableWithAllowance and hideWithAllowance are throwing the following error (using this in a script editor web part at the top of EditForm):
//group names in an array of strings, i.e. [“Group One”,”Group Two”]
var disableWithAllowance = function (fieldName, groups) {
disable(fieldName);
spContext = new SP.ClientContext.get_current();
Error = “Unable to get property ‘get_current’ of undefined or null reference”
currentUser = spContext.get_web().get_currentUser();
spContext.load(currentUser);
spContext.load(currentUser.get_groups());
I am running in a stock SP 2013 onprem environment, seattle masterpage, and referencing/using jQuery 1.10.2 (also working with 1.11.3):
My redacted script/source is the following if it helps (known good/working calling hide and disable)
http://servername/AI/jQuery/jquery-1.10.2.js
http://servername/AI/jQuery/Lozzi.Fields.js
$(document).ready(function(){
Lozzi.Fields.disableWithAllowance(“field nema”, “SharePoint Group Name”);
});
Thank you for your help
LikeLike
Sorry, formatting issue on the redacted script, trying again:
‘http://servername/AI/jQuery/jquery-1.10.2.js
‘http://servername/AI/jQuery/Lozzi.Fields.js
‘
‘ $(document).ready(function(){
‘ Lozzi.Fields.disableWithAllowance(“field name”, “SharePoint Group Name”);
‘ });
‘
LikeLike
Hi David: I was also able to reproduce the issue on an Office 365 environment (no customization/stock team site, master page, etc. AFAIK) re: disable and hide WithAllowance.
Thanks again in advance for your help.
LikeLike
Thanks for the comments. I updated the example script above, including a wait for the sp.js file. Shame on me :). Please try again with this change and let me know. I also updated the Lozzi.Fields script to fix People Picker and Metadata fields, grab the latest if you can!
LikeLike
Hi David!
I’m trying out SharePoint and needed to use your script. I was able to make it work on a sample list on O365. After editing the form using InfoPath, the script no longer apply to the fields. I even tried inserting the script in the “newifs.aspx” & “editifs.aspx” but doesn’t do anything. I tried running Lozzi.Fields.disableWithAllowance(“Status”, [“Group1”]); using Console and it returned Undefined.
Any idea on how to enable the script in an InfoPath modified form?
TIA
roy
LikeLike
Hi David!
I was trying out SharePoint 2013 and needed to use your script. I was able to use your script on a sample list. After editing the form using InfoPath in changing the layout of the fields, the script no longer apply to the fields. I tried inserting your script in the “newifs.aspx” & “editifs.aspx” but it still doesn’t work. I used the Console to execute the script but it returned “Undefined”.
Any idea on applying the script on a list modified in InfoPath?
TIA,
Roy
LikeLike
Unfortunately this won’t work with InfoPath forms. Sadly we can’t do much with JavaScript and InfoPath forms. I created this script so we wouldn’t have to use InfoPath. Since you are, you can hide fields as you need and change the form layout with ease.
LikeLike
Hy David , Can You Please Help Me , Where I Must Put This Script , Because I am Try Put In Master Page , Not Working Please Detail me , Sorry I am Newbie in Sharepoint
LikeLike
You have a couple of options. Putting it in your master page will let the code be available everywhere, but you’ll still need to put specific code on pages where you want to implement it. I usually use a Content Editor Web Part, linking to an HTML file which contains the code. Hmm.. not sure how much that helps. I’ll write up another blog post explaining how best to embed this code stuff, give me a couple of days ;)
LikeLike
Oke Thanks , It’s Working :D
LikeLike
Great tool, helped a lot. Thank you
LikeLike
I see functions for show and enable, but I get a “not supported” when I try to call these. Are the function available? I would like to conditionally enable/disable fields based on form field selections.
LikeLike
Can you confirm the script, including jQuery, is added to your page?
LikeLike
Thanks for the reply. Yes the libraries are referenced and the disable() and hide() methods function as expected. But I cannot get show() and enable() working. I am referencing jquery-2.1.4.min.js and using this in a SP2013 EditForm.aspx. Any suggestions?
LikeLike
show() and enable() are private functions, aren’t available from outside of itself. You can make them public by adding them to the return statement at the bottom of the script, like
return {
disable: disable,
disableWithAllowance: disableWithAllowance,
hide: hide,
hideWithAllowance: hideWithAllowance,
show: show,
enable: enable
}
LikeLike
Thanks David, I’ll try that. I am surprised no one ever had a need to show or enable a field after hiding it. Seems simple enough. thank you!
LikeLike
Hi David,
Thank you for your code.
I dowloaded the last version of Codeplex and also the last version of jQuery. I am using SharePont 2013. The disableWithAllowance option is working properly for the first column and rest of the column which i applied is not working on the same form, Can you help please?
Thank you
Sajesh
LikeLike
Hi Sajesh,
Can you email me the block of code you’re using and I can take a look, email to david.lozzi at slalom.com. Thanks!
LikeLike
Hi David,
I just stumbled across your plug-in. Thanks for the script. I am having problems with the disableWithAllowance setting. I am a site collection admin and part of the specified group and still cannot access the field. I have verified that Jquery is loading. For the others that were having similar issues, what was the fix?
Thank you!
LikeLike
Any errors in the dev toolbar? What does you calls to the functions look like? Specifically the Lozzi.fields….
LikeLike
no errors on the dev toolbar….
//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
/SupportFiles/Lozzi.Fields.js
$(document).ready(function(){
ExecuteOrDelayUntilScriptLoaded(function(){
Lozzi.Fields.disable(“HideField”);
Lozzi.Fields.disableWithAllowance(“HideField2”, [“My Owners”])
},”sp.js”);
});
LikeLike
Hi David,
First of all thanks a lot for your awesome work you put into the community. Im having the same problem as few others, where Lozzi.Fields.disableWithAllowance does not work and disables the field for everyone.
What i have tried:
* Developer toolbar – no errors
* Created new group – no effect
* Tested on latest Chrome, IE, Edge – no effect
System Spec:
* Win 10 Pro PL
* SharePoint Online Business Premium
* SharePoint Online E3
A beacon of hope or an element which could shed a bit of light into this mistery is that Lozzi.Fields.hideWithAllowance works as expected.
Thanks in advance.
LikeLike
Thank you for developing such a great tool.
I’ve noticed one slight issue. When disabling a lookup field (drop down) the text is replaced by the lookup ID rather than the text. Is there any easy fix for this?
LikeLike
I just came across this issue as well. I’ll be pushing an update this week.
LikeLike
Sorry for the delay, latest version now supports lookup fields.
LikeLike
I cannot save the item. because i set the item is required :(
LikeLike
Yea, unfortunately a required field is still required…
LikeLike
Hi Dave, Thanks for a great tool. Also have a issue with disabling a lookup field (drop down) cause of thext is replacing by the lookup ID. Can you provide us an update recording to this issue?
Regards
LikeLike
Just updated, should be all set now with lookup fields.
LikeLike
Hello David,
Thank you for the great tool it was very useful to me.
I read that some ppl got “undefined context” error as well as me, just surround the code with “ExecuteOrDelayUntilScriptLoaded” function and the issue will be gone.
I also did many tests and found that allowance is not working against “System” account! but work with any other account even it has the same permissions on the site/list.
Thank you
LikeLike
System Account is something special, and you really shouldn’t be using it day to day. I suggest stop using an account that logs in as such.
LikeLike
Hi David,
I love how this made my life easier :)
Is this possible in disabling the hyperlink field and just showing Click here? I tried the disable but It’s still showing the entire link. I was hoping I can change that to a link instead. (EditForm.aspx)
Thanks again!
LikeLike
Hi David,
Thank you for the great tool it was very useful to me.
I’m trying to disable the choice field(radio button) but it’s not working properly. it will disable the field but will add extra text of “ctl100” before the Options. Please tell me how to deal with this.
I have also got the same issue that Lozzi.Fields.disableWithAllowance is not working properly. The field gets disabled for everyone. I’m using latest Lozzifield.js
LikeLike
I see the issue, and am working a fix now, however I don’t see ctl100 in my example. How many choice options do you have? Can you email me a screen shot? david.lozzi at slalom.com
LikeLike
Just released update to support choice fields as radio buttons. download and let me know!
LikeLike
Hello David,
Thank you for your amazing work with your lozzi.fields.
I experienced a little issue when disabling a Date/Time field.
I use a Date/Time field with Date and Time. If I disable this field, it only shows the date but not the time.
For Example:
08/15/2016 12:00 AM is shown as 08/15/2106 if I disable this Date/Time field with Lozzi.Fields.disable(“Date/Time field”)
Any idea how to solve this problem?
Thank you!
LikeLike
This isn’t working for my site. I put the following into a Script Editor web part on the EditForm.aspx page:
//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
/SiteAssets/Lozzi.Fields.js
$(document).ready(function(){
ExecuteOrDelayUntilScriptLoaded(function(){
Lozzi.Fields.disable(“Title”);
},”sp.js”);
});
The script is running. There are no errors in the console. I am using SharePoint 365. The title field still shows up. I am using Chrome as my browser. Am I missing something?
LikeLike
Hi David,
Thanx for your outstanding work,
Like Patrick, I wonder how to be able to still see the time when disabling the date/time field.
LikeLike
Hi,
can anyone tell me whats sp.js?
Thanks
LikeLike
It’s one of SharePoint’s default JavaScript libraries. It’s needed to perform most tasks against Sp
LikeLike
Hi
I am having an error with the disableLookupField.
Disable works for all my other fields, but as soon as I add the disable to a field with a drop down list, it stops working for all of them.
jquery-3.1.1.min.js:2 jQuery.Deferred exception: theControls is not defined ReferenceError: theControls is not defined
at disableLookupField (/Scripts/Lozzi.Fields.js:75:21)
Do you know what could be causing this?
Thank you
LikeLike
I have now created a custom Edit form as we also needed to change to of the field name text colours. I now have the following issues:
1) The lookup field is now disabled, but it only shows the ID, not the line of text.
2) The people picker field now displays this way:
21;#Name
Enter users separated with semicolons.
It worked on the default EditForm.aspx
Are you able to assist with this?
As an aside, is there a way that I could incorporate the colour change into this script instead of creating a new edit form?
The columns I have are Task status (drop down list) and Comments (multiple line text field) I’d like on the form itself that the words “Task Status” and “Comments” be displayed in red.
Thank you
LikeLike
Hello. Tried this, but /SiteAssets/Lozzi.Fields.js is “Not Found”. Has this changed or is this now defunct? Thanks.
LikeLike
That would depend on where you uploaded the file to your SharePoint site.
LikeLike
Thank you for this tool. I am disabling a lookup field and while the field is being disabled, it is displaying the ID and not the Title field of the lookup. Is it possible to display the Title field and not the ID?
LikeLike
Ah, interesting, I’ll take a look.
LikeLike
Hi bob – I wasn’t able to recreate the issue. The code as is appears to work. Can you email me at david.lozzi at slalom.com and we can troubleshoot further?
LikeLike
Hey David!
You did an awesome Job putting this together!
I stumbled over one thing though: When i downloaded the latest version of your library i recognized that the return value ‘show’ was missing. Is this on purpose, since unhiding fields would be impossible that way.
greetings,
Alex
LikeLike
Which function are you looking at specifically?
LikeLike
The Lozzi.Fields function, in the return section (Line 241 – …) return {
disable: disable,
disableWithAllowance: disableWithAllowance,
hide: hide,
show: show,
hideWithAllowance: hideWithAllowance,
setDefaultValue: setDefaultValue
}
The show argument was missing
LikeLike
Whoa good catch, I’ll update!
LikeLike
Hi there,
Great script! Thanks for sharing.
I’m having issues hiding the Title field on the display form. Does your script support this/
thanks
LikeLike
I think this works on Display forms too, to be honest I forget. Are you getting any errors?
LikeLike
Hi David,
Thank you so much for the code.
Can I know if .setDefaultValue can be used? How do I used it?
LikeLike
Unfortunately it looks like I didn’t finish that. It may work for a choice column as a dropdown, otherwise nothing else.
LikeLike
Hi David, DisableWithAllowance and HideWithAllowance is not working for me. I set up a group called test members. The code should show the permission field for users in the test members group. Instead it hides the field from everyone.
$(document).ready(function(){
ExecuteOrDelayUntilScriptLoaded(function(){
Lozzi.Fields.hideWithAllowance(“permission”, [“test members”]);
},”sp.js”);
});
LikeLike
My immediate guess is the group name might be case sensitive. Give that a try. Also, in the dev toolbar (press F12 to open) are there any errors?
LikeLike
Thank you for the immediate reply. The group name is case sensitive. Fixed the case and it works.
LikeLiked by 1 person
Great! Thanks for YOUR quick reply ;)
LikeLike
Hi David,
Just wanted to confirm a constraint to make sure it’s not a user error on my part. When using the allowance option, am I correct in that it can’t recognize AD groups within a SharePoint group? Tried and it only seems to work when each person is added directly to the SharePoint group.
Great script by the way. Been looking for something like this for sometime :)
Thanks,
Kevin
LikeLike
Nice catch, haven’t seen that tried yet but that makes sense. I think SPs APIs in use don’t traverse into AD groups.
LikeLike
Hi David,
Thanks a lot for this ! I’ve been searching high and low for ages now to find a solution to hide form fields, tried your one and it worked first time !
I just had one question, do you know if it would be possible to hide certain fields depending on the value of another through the use of your script ?
I have a work type column with different choices and would like to hide certain fields depending on what work type was selected. Any ideas if I could achieve this with your script ?
Thanks again,
Ryan
LikeLike
Hi David,
Managed it with the help of jQuery and your script!
Thanks again
LikeLike
Excellent!
LikeLike
David Give an Help, Your Script works very Well but i have an Problem with Disable and disableWithAllowance :
– Comboboxes with values that are in another list he shows the ID of the list not the Value Example If I have a list of names it shows one value: 3 or 4 or 5
– Comboboxes with Values defined in this list it shoes for example: ctl00 and not the name
– People picker it shoes for example: 70;#Sam,#Sam,#,#,#Sam,#,#,# When the choice selected is “Sam”
Can i get arround of this? I understand that he is showing me the Ids of the selections of combobox but i need the value in people picker it appear to show the id+value but i not understand the rest..
Thank you very much
LikeLike
Thanks for the info back. I’ll take a look at the code in the next few days.
LikeLike
Sorry for the delay, but I finally got around to looking into this. I can’t seem to recreate your issues on my end. If you’d like, email me, david.lozzi at slalom.com and we can continue to look further.
LikeLike
David, thank you very much for this script. I am working with SharePoint for some time but just recently found this and it really made my life much easier :-)
What i think it would be great feature is if you could make some fields visible or hidden for everyone except item creator (person in “created by” field).
Again, thank you very much for sharing this wonderful script.
LikeLike
Great idea! I’ll check it out.
LikeLike
Hi Davide, congratulation for your script, and many thanks for sharing.
It’s very useful.
I have a question for you regarding multiple choice checkbox.
If I disable it for modification I cannot understand which option are selected.
for example:
if checkbox disabled:
Variante
on
Alzatina posteriore
Attacchi acqua anteriori
Attacchi acqua posteriori
Barra antirollio
Carico Acqua automatico
Controllo picchi
Corrimano
Foro miscelatore
Variante
(checked) Alzatina posteriore
(checked) Attacchi acqua anteriori
Attacchi acqua posteriori
(checked) Barra antirollio
Carico Acqua automatico
(checked) Controllo picchi
Corrimano
Foro miscelatore
Am i wrong?
many thanks again
Renis
LikeLike
I’ll take a look!
LikeLike
Download the latest version and give it a try! Should work as expected now.
LikeLike
Hi, thanks a lot for your quick answer!
Seems not working now, here the console log.
jquery-3.3.1.min.js:2 Uncaught TypeError: Cannot read property ‘indexOf’ of null
at Object.disable (Lozzi.Fields.js:28)
at Modifica.aspx?ID=283&xxxxxMareno.aspx:552
at ExecuteOrDelayUntilEventNotified (init.js:1)
at ExecuteOrDelayUntilScriptLoaded (init.js:1)
at HTMLDocument. (Modifica.aspx?ID=283&Source=httpsxxxxMareno.aspx:551)
at l (jquery-3.3.1.min.js:
at c (jquery-3.3.1.min.js:2)
if I restore previous version is ok.
thanks
Renis
LikeLike
Can you confirm what page you’re putting the script on? I see Modifica.aspx, is that the edit screen?
LikeLike
Yes, it’s the edit screen.
ty
LikeLike
Hmmm… I see you’re using jQuery 3.31, so I updated my version accordingly and it still works as expected.
What version of SP are you running on?
Can you Inspect your field in dev toolbar (right click on the field and select inspect) and expand the HTML out and send me a screen shot of the field? Email me at david.lozzi at slalom.com. It looks like your SP might be missing some expected content.
LikeLike
Ah, it’s prbably a language issue, I’m looking for a comment with the workds FieldName in it, which it looks like your SP wouldn’t have. So, I’ve applied a fix, give the latest a try.
LikeLike
Wonderful! the last version solved the problem!
many thanks and congratulation for your great job!
Renis
LikeLike
Excellent, thanks for working with me on it! Cheers!
LikeLike
Hi David, just a thought,
what do you think of a function to color the line?
it might be useful to separate the sections of the form.
regards
Renis
LikeLike
I like it. could add a form break, provide color code and height, along with a title field, which would highlight a field providing a code… sounds easy enough! I’ll see what I can do
LikeLike
Sorry, I mean color a row, like hide or disable.
I hope i was pretty clear, my english is not so good! Thanks
LikeLike
I follow you, I added to it ;)
LikeLike
Greetings David,
Thank you for your work.
I hesitate posting after reviewing this page going back to 2015. But I’m having a similar error with the hideWithAllowance and disableWithAllowance. I’m getting a JS error:
fields.spContext.load(fields.currentUser);
fields.spContext.load(fields.currentUser.get_groups());
fields.spContext.executeQueryAsync(() => {
fields.getGroupsAndShow(fieldName, groups);
}, asyncFailed); <———————————————————-RED ERROR BALL
},
***Lozzi.Fields.js:277 Uncaught ReferenceError: asyncFailed is not defined at Object.hideWithAllowance (Lozzi.Fields.js:277) ***
We are using 2013 on prem SP. Error occurs in IE and Chrome.
Basically, the hide works regardless of membership in the group; the hide always hides. The disable doesn't work at all.
My code within a html file.
//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
/sites/InfoSecHome/IAM_MRBA/SiteAssets/Lozzi.Fields.js
$(document).ready(function(){
ExecuteOrDelayUntilScriptLoaded(function(){
Lozzi.Fields.hideWithAllowance(“TestHide_Field”, [“MRBA Waiver Owners”]);
Lozzi.Fields.disableWithAllowance(“ReadOnly_Field”, [“MRBA Waiver Owners”]);
},”sp.js”);
});
I appreciate any feedback you can give.
Thank you in advance,
Donovan Quesenberry
LikeLike
Can you try the latest version from github? I have it working with most fields, though not people fields. Let me know.
LikeLike
I have the latest and greatest and testing in Chrome (v 77 64 bit) and IE (v11). The functions seem to be working as before. Not a thorough test, but probably 60% coverage. The new features (Multi-user and IE) specifically are working in both Chrome and IE. Having this library available really makes the UA more user-friendly and keeps it much tighter to prevent mishaps.
LikeLiked by 1 person
Awesome thanks for testing it out!!
LikeLike
Hello. Thanks for this. I am having a problem getting this to work in IE. In chrome it works a dream but in IE I get an error that lozzie is undefined….
LikeLike
Can you share your code snippet where you’re using it?
LikeLike
I just implemented this in Chrome and found it was working great. After seeing your post, I too have issues in IE. Did you get a fix?
LikeLike
Not yet, thanks for the reminder. I will aim to work on it by this weekend 😁
LikeLike
Did you ever resolve your issue. I get the exact same error. I include my reference in my Edit screen
LikeLike
Issue fixed in IE. Sorry about that, I shamefully forgot IE doesn’t support ES6
LikeLike
Should be all set to go now with the latest version!
LikeLiked by 1 person
A couple of enhancements I might suggest.
1. Defaults for some fields are very changeling and require code. Defaulting a people-picker to the current user is a common default
2. Comparison formulas – is field x == Y. You could start out simple and not include other operators as > or <
Just some thoughts. Thank you for developing these.
LikeLiked by 1 person
I like these ideas. I explored setting a default user, and frankly, that was really difficult, as the name you see if a lot more than just a name.
I like the comparison formulas idea, mind throwing that up on git as a feature request in the issues list? We’ll see what I can do ;)
LikeLike
Looks like you do not support the fieldtype=SPFieldUserMuti. I updated my version of your code to support this option and called the diesalePeoplepicker method. Works fine for a single name in this fieldtype and works fine for multiple names with the exception of leaving the x’s there to allow the user to delete a name.
Lastly, I still can’t seem to call your functions from IE 10. It has Lozzi undefined. Thanks
LikeLike
wanna share the code? :D And I have it on my list this week to fix/confirm. Thanks!
LikeLike
I can, but I really didn’t do anything except add the new option for SPFieldUserMuti which is exactly the same code you were using for SPFieldUser. I didn’t have the time to figure out how to remove the “x” when there were multiple names. That seems like the only change that is needed from that of SPFieldUser.
LikeLike
FIXED! Latest version has multi-user support now for people fields, working in IE ;)
LikeLike
Hi Lozzi,
I am getting strange results scripts works for me but only hides the text box not the Label of TextBox.
can you comment on this ?
LikeLike
Can you provide a snippet of what you’re doing?
LikeLike
Hi ,
i am getting one issue while using your script.
script only hides the textbox but not the label of the textbox.
please reply..
e.g Name : TextBoxField(Input)
it hides Textbox and remain show the label
LikeLike
What’s your SharePoint? What type of list? What type of field(s)? Which browser and version? What’s your syntax? Which jQuery are you including? Any errors being thrown (look at console).
LikeLiked by 1 person
how can i upload snippet here, i am using sharepoint online
LikeLike
You can just copy/paste it here
LikeLike
David i cant copy/paste here,
Please share your email id or let me explain again
i have field Address
when i apply your script to hide Address field from certain sharepoint group.
Address : abcAddressOfPerson
it hides “abcAddressOfPerson” but the label “Address : ” remain shown on form.
i am using sp online
LikeLike
It might be your syntax. Here I’m using the his library. var admingroup = “BSM Request Admins”;
Lozzi.Fields.disableWithAllowance(“Request Phase”,[admingroup]);
LikeLike
sure! email me at david.lozzi at slalom.com
LikeLike
David,
it worked. you have made my life easy.
Thanks
LikeLiked by 2 people
David,
There is one thing I want you to help me.
I have a form have multiple headings
– Employee info
– Supervisor Remarks
I have hidden all the fields of “Supervisor Remarks” from Employee but the heading “Supervisor Remarks” is shown to Employee.
I want to hide the heading “Supervisor Remarks” as well from the employee. script for heading creation.
$(function () {
//set section text and field name
AddSectionBeforeField(“Employee Information”,”Employee Code”);
AddSectionBeforeField(“Supervisor Remarks”,”Supervisor Recomendation”);
});
function AddSectionBeforeField(sectionText,fieldName){
var $fieldTR=$(“.ms-standardheader nobr:contains(‘”+fieldName+”‘)”).closest(“tr”);
$fieldTR.before(“”+sectionText+””);
}
is it applicable using your script “Hidewithallowance()”
LikeLike
I use this function as well, but found that it does not work on a displayForm. In addition, adding ID to display I found very useful but I had to change the above code to Add a section before the ID.
LikeLike
This script doesnot work with custom forms(New,edit,disp) :-(
LikeLike
Right, it’s specifically looking for how SharePoint does it. If you have a custom form you can replicate this within your code set probably easier. The goal here was to provide capabilities to out of the box forms.
LikeLike