SharePoint Column fields show or hide depending on Drop down selection - sharepoint

For one of the lists, I have to hide column Project (single line of text) based on the choice column 'Customer' drop down selection. I have two values in customer drop down: Customer W Project and Customer WO Project. If the user selects Customer W Project, I want to hide Project column field on the new item click form. Below is the code I am using, please let me know if anything is wrong:
Also, I am working on SharePoint 2016 online/office 365.
Any help will be greatly appreciated. Thanks.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js></script><script src="/sites/lcpatest/Style%20Library/sputility.js"></script>
<script> $(document).ready(function(){
var customer = SPUtility.GetSPField('Customer');var HideOrShowOthersField=function(){var customerValue = customer.GetValue();
if(customerValue=='Customer W Project'){SPUtility.GetSPField('Project').Hide();
}else {SPUtility.GetSPField('Project').Show();}};HideOrShowOthersField();
$(customer.Dropdown).on('change',HideOrShowOthersField);});</script>

Your jQuery library is so old.
Below code works based on my testing.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="/sites/Developer/SiteAssets/sputility.js"></script>
<script>
$(document).ready(function () {
var customer = SPUtility.GetSPField('Customer');
var HideOrShowOthersField = function () {
var customerValue = customer.GetValue();
if (customerValue == 'Customer W Project') {
SPUtility.GetSPField('Project').Hide();
}
else {
SPUtility.GetSPField('Project').Show();
}
};
HideOrShowOthersField();
$(customer.Dropdown).on('change', HideOrShowOthersField);
});
</script>

Related

show/hide tr on dropdown selection for a list in sharepoint

I have created a list in sharepoint now in newform I'm trying to hide and show 3 tr alternatively when i click on dropdown value. for eg: I have 3 option in dropdown A, B, C and my tr have ids(A, B, C) click on A only A is there when B only B is there and when C only C is there. same for edit form how to achieve this?
Sample tested script for a previous thread( I can't remember the link), you could update the script based on your fields' definition.
SPUtility.js
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="/siteassets/sputility.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
var employeetype = SPUtility.GetSPField('Employee Type');
var showOrHideField = function () {
var employeeValue = employeetype.GetValue();
if (employeeValue == 'Existing Employee') {
SPUtility.GetSPField('Employee Name').Show();
SPUtility.GetSPField('Employee ID').Show();
SPUtility.GetSPField('Candidate Name').Hide();
}
else {
SPUtility.GetSPField('Employee Name').Hide();
SPUtility.GetSPField('Employee ID').Hide();
SPUtility.GetSPField('Candidate Name').Show();
}
}
// run at startup (for edit form)
showOrHideField();
// make sure if the user changes the value we handle it
$(employeetype.Dropdown).on('change', showOrHideField);
});

Sharepoint : Fire Jquery after upload document library

I am new to sharepoint development and my task is to hide certain columns in a document library I managed to do it with jquery but the problem when I add a document to my library the jquery does not activate and the columns will be unmasked again Thanks for your help
If you want to hide columns in document library list view, we just modify the list view and uncheck the columns in this list view.
Show or hide columns in a list or library
If you just want to use jQuery to achieve it. The following code for your reference.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function (ctx) {
//add column name
var columns=["column1","column2"];
//hide columns
hideColumns(columns);
}
});
});
function hideColumns(columns){
for(var i=0;i<columns.length;i++){
var columnIndex=0;
$(".ms-listviewtable>thead>tr>th").each(function(index){
if($(this).text().indexOf(columns[i])!=-1){
columnIndex=index;
$(this).hide();
}
});
$(".ms-listviewtable>tbody>tr").each(function(i){
$(this).children("td").eq(columnIndex).hide();
});
}
}
</script>

how to autopopulate a column based on another column

I have a column name "work code" with choices off/work/leave and another column name "transport Refund" with choices none/refund. If I choose OFF in work code I need to have automatically a "NONE" in Transport refund column.
How can I do it
Add the code below into a script editor web part into new/edit form page.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("select[title='work code']").change(function(){
if($(this).val()=="off"){
$("select[title='transport Refund']").val("none");
}else{
$("select[title='transport Refund']").val("");
}
});
});
</script>

Message box on selected index change

I am trying this JavaScript code to give user a message when selected item from a drop down list contains "Ultra Low" but is not working. Can someone please help?
<script language="javascript" type="text/javascript">
var dropdown = document.getElementById("ddGlass");
dropdown.onchange = function (event) {
if (dropdown.str.indexOf("Ultra Low") > -1) {
alert("Glass Option is for Yuma Only")
}
}
</script>
Where did you get dropdown.str? It should be dropdown.value.

Sharepoint navigation menu collapse

Does anyone know when in sharepoint you´ve created a navigation structure in site settings navigation / that i can only add a page under a heading and have to hide the page which is the heading?
How I can make the menu collapse when clicking on the top menu rather then immediate display?
I want to display the second level when clicking on any of the first and then when clicking on the second for the first to dissapear and the 2nd and 3rd to be displayed and the breadcrum to easily go back home.
How can this be done in the portal not with publishing sites? Any advice would be greatly appreciated.
Jquery is the way:
<script type="text/javascript" src=http://yourMoss/sites/Shared%20Documents/jquery-x.x.x.js></script>
<script type="text/javascript">
$(function(){
//initialize menus
var menuRows = $("[id$='QuickLaunchMenu'] > tbody > tr");
var menuHd = menuRows.filter("[id!='']:has(+tr[id=''])");
//set img path for when submenu is hidden
var closedImg = "/_layouts/images/plus.gif";
//set img path for when submenu is visible
var openedImg = "/_layouts/images/minus.gif";
var cssInit = {
"background-image": "url('"+closedImg+"')",
"background-repeat": "no-repeat",
"background-position": "100% 50%"
}
var cssClosed = {"background-image": "url('"+closedImg+"')"}
var cssOpen = {"background-image": "url('"+openedImg+"')"}
//hide submenus
menuRows.filter("[id='']").hide();
//apply initial inline style to menu headers
menuHd.find("td:last").css(cssInit);
menuHd.click(function () {
var styleElm = $(this).find("td:last")
var nextTR = $(this).next("tr[id='']");
if (nextTR.is(':visible')) {
nextTR.hide();
styleElm.css(cssClosed);
} else {
nextTR.show();
styleElm.css(cssOpen);
}
});
});
</script>

Resources