Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 124
  • Last Modified:

.removeAttr() not working in my SharePoint JSOM code

I had this question after viewing Remove 'disabled' attribute.  I implemented the same code below in a list that is generated dynamically but it's not working.  

One of the fields should get disabled if user is in the SharePont 'Manager' group but nothing happens.  If you would like the creds to my SharePoint site so you can see for yourself.  Let me know and I will send you the creds to your inbox.  Thanks!


jQuery(document).ready(function () {
    SP.SOD.executeOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");  
    
 console.log("Entering SPServices");
	$().SPServices({
 		operation: "GetGroupCollectionFromUser",
 		userLoginName: $().SPServices.SPGetCurrentUser(),
 		async: false,
 		completefunc: function (xData, Status) {
 		console.log(xData.responseXML.xml);
		if ($(xData.responseXML).find("Group[Name='Manager']").length == 1) {
 			$('[id^=faRowID]').removeAttr('disabled');
 		}
 		else {
 			alert("login outside of the Group user");
 		}
	  }
 
	}); /*close().SPServices({ */        
});

	/*New to make this dynamic-had to get it working first.*/
	var htmlTbl = "<table border='0' cellspacing='5' cellpadding='5'>"+
			  "<tbody>"+
			  "<tr><td class='bold'>Minimum Cost:</td><td><input type='text' id='min' name='min'></td></tr>"+
			  "<tr><td class='bold'>Maximum Cost:</td><td><input type='text' id='max' name='max'></td></tr>"+
			  "</table>"+
	    	  "<table id='prioritize' class='display' cellspacing='0' width='100%'>"+
	          "<thead>"+
		          "<th>ID</th>"+
		          "<th>Project Title</th>"+
		          "<th>Facility Priority</th>"+
		          "<th>VISN Priority</th>"+
		          "<th>National Priority</th>"+
		          "<th>Project Number</th>"+
		          "<th>VISN</th>"+
		          "<th>Station</th>"+
		          "<th>Total Project Cost</th>"+
		          "<th>Design Fiscal Year</th>"+
		          //"<th>Construction Fiscal Year</th>"+
	          "</thead>"+
	     	  "<tbody>";


	//Retrieves all list items- Will need to modify to take in query string data to pass to CAML.
	function retrieveListItems() {
		var clientContext = new SP.ClientContext();
		var oList = clientContext.get_web().get_lists().getByTitle('Project Module');
		
		var camlQuery = new SP.CamlQuery();
	  
		this.collListItem = oList.getItems(camlQuery);
		
		clientContext.load(collListItem);
		
	    clientContext.executeQueryAsync(
	        Function.createDelegate(this, this.onQuerySucceeded),
	        Function.createDelegate(this, this.onQueryFailed)
	        );
	}

	function onQuerySucceeded(sender, args) {
	    var listItemInfo = '';
	    var listItemEnumerator = collListItem.getEnumerator();		
	
		var i = 0;
	    while (listItemEnumerator.moveNext()) {
	        var oListItem = listItemEnumerator.get_current();

			
	        htmlTbl += "<tr><td class='NRM_pj_align'>" + oListItem.get_item('ID') + "</td>" +
    		"<td class='NRM_pj_align'>" + checkForNull(oListItem.get_item('Title')) + "</td>"+
			"<td class='NRM_pj_align' data-order="+oListItem.get_item('Faciltity_x0020_Priority')+"> "+
            "<input type='text' size='1' disabled name = 'RowID-" + oListItem.get_item('ID') + "' id='faRowID-" + oListItem.get_item('ID') + "' data-curVal=" + oListItem.get_item('Faciltity_x0020_Priority') + " value=" + checkForNull(oListItem.get_item('Faciltity_x0020_Priority')) + ">"+
            "</td>" +
            
			"<td class='NRM_pj_align' data-order="+oListItem.get_item('VISN_x0020_Priority')+"> "+
            "<input type='text' size='2' disabled name = 'RowID-" + oListItem.get_item('ID') + "' id='viRowID-" + oListItem.get_item('ID') + "' data-curVal=" + oListItem.get_item('VISN_x0020_Priority') + " value=" + checkForNull(oListItem.get_item('VISN_x0020_Priority')) + ">"+
            "</td>" +
            
			"<td class='NRM_pj_align' data-order="+oListItem.get_item('National_x0020_Priority')+"> "+
            "<input type='text' size='2' disabled name = 'RowID-" + oListItem.get_item('ID') + "' id='naRowID-" + oListItem.get_item('ID') + "' data-curVal=" + oListItem.get_item('National_x0020_Priority') + " value=" + checkForNull(oListItem.get_item('National_x0020_Priority')) + ">"+
            "</td>" +
            				        
			"<td class='NRM_pj_align'>" + checkForNull(oListItem.get_item('Project_x0020_Number')) + "</td>"+	        
			"<td class='NRM_pj_align'>" + checkForNull(oListItem.get_item('VISN')) + "</td>" +
			"<td class='NRM_pj_align'>" + checkForNull(oListItem.get_item('Station_x0020_Name')) + "</td>" +

			"<td class='NRM_pj_align'>" + checkForNull(oListItem.get_item('Total_x0020_Project_x0020_Cost')) + "</td>"+	        
			"<td class='NRM_pj_align'>" + checkForNull(oListItem.get_item('Design_x0020_Obligation_x0020_Da')) + "</td></tr>";
			//"<td>" + oListItem.get_item('Construction_x0020_Obligation_ ') + "</td></tr>";

		}
		
			htmlTbl += "</tbody></table>";
		
			$("#divListItems").html(htmlTbl);
			

	 	/*Apply DataTable style */
     	var table = $('#prioritize').DataTable();     
	    // Event listener to the two range filtering inputs to redraw on input
	    $('#min, #max').keyup( function() {
	        table.draw();
	    } );  

	
	}
	
	$.fn.dataTable.ext.search.push(
	    function( settings, data, dataIndex ) {
	        var min = parseInt( $('#min').val(), 10 );
	        var max = parseInt( $('#max').val(), 10 );
	        var totProjCost = parseFloat( data[8] ) || 0; // use data for the age column
	 
	        if ( ( isNaN( min ) && isNaN( max ) ) ||
	             ( isNaN( min ) && totProjCost <= max ) ||
	             ( min <= totProjCost && isNaN( max ) ) ||
	             ( min <= totProjCost && totProjCost <= max ) )
	        {
	            return true;
	        }
	        return false;
	    }
	);
	
	
	function checkForNull(val) {
		if (val === null) {
			return " ";
		}else {return val;}
	}

Open in new window

0
Isaac
Asked:
Isaac
  • 4
  • 4
1 Solution
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Here's my html file

<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">

<script src="/Webpart/JavaScript%20Library/js/jquery.js"></script>

<link rel="stylesheet" type="text/css" href="/Webpart/JavaScript%20Library/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="/Webpart/NRM/projectModule.css">
<script type="text/javascript" src="/Webpart/JavaScript%20Library/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/Webpart/JavaScript%20Library/js/jquery.SPServices-2014.02.js"></script>
<script type="text/javascript" src="/Webpart/NRM/priorityModule.js"></script>

<div id="divListItems"></div>

Open in new window

0
 
leakim971PluritechnicianCommented:
Place an alert to confirm :
alert( "found: " + $('[id^=faRowID]').length + " and its value is: " + $('[id^=faRowID]').attr('disabled') );
$('[id^=faRowID]').removeAttr('disabled');

Open in new window


if you get at least 1 please send me your creds.
0
 
leakim971PluritechnicianCommented:
also try this :
jQuery('[id^=faRowID]').removeAttr('disabled');
instead :
$('[id^=faRowID]').removeAttr('disabled');
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Neither one of those worked.  The alert never generated only when I went into developer mode (f12). See image below:

alert
0
 
leakim971PluritechnicianCommented:
so found 0, if no element found, how do you want to remove the disabled attribute ?
as you can see, the browser need a bit of time to draw/generate the table.
the bad way is to add a timer :
So you replace :
jQuery('[id^="faRowID"]').removeAttr('disabled');

Open in new window

by :
setTimeout(function() { 
   $('[id^="faRowID"]').removeAttr('disabled'); 
}, 5000); // wait 5 seconds before removing the disabled attribute

Open in new window

0
 
leakim971PluritechnicianCommented:
look like you find the good way and use SP.ClientContext.executeQueryAsync(succeededCallback, failedCallback) which throw once the table is completed and drawed, could you please close the question?
For any further reference : https://msdn.microsoft.com/en-us/library/office/dn168907.aspx
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
It's still not behaving the way I would hope.  When you go to the next page, the boxes become disabled.  I will close the ticket though and open up another question.  Thanks!
Adding the double quotes helped with a slight variation.

jQuery('input[id^="faRowID"]').removeAttr('disabled');
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
jQuery('input[id^="faRowID"]').removeAttr('disabled');
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now