There are certain requirements when creating a new item in the SharePoint custom list user has to hide certain columns based on other value. There are two different ways to achieve it:
- Server side
- Client side
In Server side, we need to write our WebPart and add the webpart to the new form of the list and close the default one. In this, you have full control of the controls and life cycle. But the pain lies in the deployment and maintaining the code. The advantage is that we have full control and the webpart and flexibility to achieve any kind of validations.
- Edit the new form and add CEWP to the form.
- Change the chrome state to none, we don't want to see the webpart title. It's meant to be invisible to the end users.
- In the HTML view of the CEWP, add the below code snippet.
- Change the
HideColumn function parameters based on your columns in the custom list.
That's it! Try to add a new item to the list, and based on the column values the other column will get hidden in the code. I have used check box and text field. Based on check box, I'm deciding here whether to show or hide the column.