This project has moved and is read-only. For the latest updates, please go here.

Hiding fields in SP2013 Edit Form

Feb 26, 2015 at 9:57 PM
Hi there,

I am trying to hide fields in a SP2013 Edit Form on a standard custom list based on a value in another field on the same form, but before getting to that stage I thought I would test if I could simply hide a field in the Edit Form.

I have had no success in being able to hide the field. I checked that my install was working correctly with the "Hello World" test, but the EditForm will not hide my field called "Week Ending"

Any insights..

<script src="/SiteAssets/SPUTILITY/jquery-1.11.2.js"></script>
<script src="/SiteAssets/SPUTILITY/sputility.min.js"></script>
<script>
<script type="text/javascript"> // wait for the window to load Event.observe(window).load(function () { SPUtility.GetSPField('Week Ending').Hide(); }); </script> ====================================================

Appreciate any help or thoughts as I am learning as I go and have got stuck at this point.

Thanks in advance.
Feb 27, 2015 at 12:59 AM
Edited Feb 27, 2015 at 1:00 AM
Thanks for posting a new discussion (helps me keep things organized). :)

Can you tell me where you got the code sample above? It is still using the prototype.js functions instead of jQuery.

Try this code instead:
<script src="/SiteAssets/SPUTILITY/jquery-1.11.2.js"></script>
<script src="/SiteAssets/SPUTILITY/sputility.min.js"></script>
<script>
// wait for the window to load
$(window).load(function () {
    SPUtility.GetSPField('Week Ending').Hide();
});
</script>
You can check out more code examples here.
Feb 27, 2015 at 3:18 AM
Thanks for responding, I really appreciate it.

The code was built up from older examples from here on blogs, so I am guessing I was using old/out of date code. Sorry..

The code you provided worked in a limited way, so let me explain exactly what I am doing and you can confirm if I am using the right approach.

I am attempting to hide a field in the EditForm.aspx default Edit Form for a custom list in SP2013.

How I am attempting to do this is by placing a CEWP in the EditForm.aspx screen above the web part that contains all the fields in the default screen.

I then placed your code into notepad and saved as a HTML file and saved it in the Site Assets folder of the subsite

Then I went back into the CEWP and provided the link to the html file where directed in the Edit webparts properties.

When I click OK the field disappears, but once I save the screen and exit the screen edit mode and return to the custom list, select a record and edit it in the same form, the code seems to have no effect and the field is still visible.

Is my approach or technique not correct or is there a reason why the EditForm.aspx won't respond to code in a CEWP that is placed in the form like this.

Thanks again for your help.

Rob.
Feb 27, 2015 at 5:17 AM
Rob,
I'm very sorry but apparently I didn't test very well and I found a bug in version 0.11.0!

Can you please re-download a new version of SPUtility (v0.11.1) and see if that fixes your issue?
Thanks,
Kit
Feb 27, 2015 at 10:56 PM
Thank you!!!

This worked perfectly with the update and the previous code you provided.

Based on your example I then used https://github.com/kitmenke/sputility/blob/master/examples/dropdownchange.html
to build out a conditional hiding of fields.

However the line that hides the City field differs from the example you provided me. I tried both ways and found the method of hiding the field you provided me worked over the example in the link.

Not sure why but just thought I would let you know just in case you need to update your example to this new method.

Once again thank you so much, you solved a problem that had me completely lost for a week!!

Thanks
Rob.
Feb 28, 2015 at 2:34 PM
Great! I'm glad you got it working.

Thanks for letting me know about the other example. I'll check it out.
Mar 3, 2015 at 4:02 AM
Edited Mar 3, 2015 at 4:03 AM
Hi Kit,

A quick update on the above issue.
When testing the above solution I was working on our "on-premise SP 2013" version.
Now when I take the exact same code and 2 source files (jquery amd sputility) into SP Online (Office 365) the same situation occurs that was originally happening at the start of this thread.

I add the link to the code whilst editing the web part and click OK to save the Web Part settings, the fields are then hidden. When I go to save the page and then subsequently return to the EditForm the code does not appear to work.
This is exactly the issue previously that you fixed with a new release, but of course that whole scenario that then worked was inside "on-premise SP2013", now in "Office 365" the same is occurring.

Thoughts.

Thanks
Rob.
Mar 4, 2015 at 2:19 AM
Rob,
I tested with Office 365 SharePoint 2013 and I'm not seeing the same issue. Can you add a try/catch around your statements to see if you're getting an error? You can also check the developer console.
<script src="/SiteAssets/SPUTILITY/jquery-1.11.2.js"></script>
<script src="/SiteAssets/SPUTILITY/sputility.min.js"></script>
<script>
// wait for the window to load
$(window).load(function () {
    try {
        SPUtility.GetSPField('Week Ending').Hide();
    } catch (e) {
        alert(e);
    }
});
</script>
Thanks,
Kit
Mar 4, 2015 at 5:47 AM
Edited Mar 4, 2015 at 5:48 AM
Thanks Kit,

I added your code and re-ran it but nothing happened in terms of seeing an error message on the screen with same behavior.

Is there another location I need to see this error?

Where do I need to go to see the developer console?

Thanks
Rob.
Mar 5, 2015 at 1:00 AM
Hmm... weird. It should have popped open an alert window if there was an error running SPUtility.js code. Maybe jQuery isn't being loaded?

Depending on your browser, there are different ways to open the developer console. Usually the shortcut is F12.
Jul 9, 2015 at 10:30 AM
Hello Kit,

I'm trying tu use SPUtil to hide a field named keuze.
I know the field exsists
the alert when wrapping the code in Try{ } catch{alert} says : 'Unable to get SPField named keuze'

the console tells me:
Failed to load resource: net::ERR_CACHE_MISS
2https://[url of site]/_layouts/15/images/blank.gif Failed to load resource: net::ERR_CACHE_MISS

using jquery 1.11.3.min
Jul 9, 2015 at 1:56 PM
SanderSmit,
Sorry to hear you are having trouble. Can you please create a new discussion?

Also, one thing to try is the "getting started" page I created: https://github.com/kitmenke/sputility/blob/master/examples/gettingstarted.html

Just follow the instructions at the top of the file and let me know what output you get.
Thanks,
Kit