Advertisement
iamthehxc

Untitled

Feb 27th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
  2.  
  3. <script type="text/javascript">
  4. $(document).ready(function() {
  5.  
  6. HillbillyCascade({
  7. parentFormField: "State", //Display name on form of field from parent list
  8. childList: "Cities", //List name of child list
  9. childLookupField: "Title", //Internal field name in Child List used in lookup
  10. childFormField: "City", //Display name on form of the child field
  11. parentFieldInChildList: "State" //Internal field name in Child List of the parent field
  12. });
  13.  
  14. });
  15.  
  16. function HillbillyCascade(params)
  17. {
  18.  
  19. var parent = $("select[Title='"+params.parentFormField+"'], select[Title='"+
  20. params.parentFormField+" Required Field']");
  21.  
  22. $(parent).change(function(){
  23. DoHillbillyCascade(this.value,params);
  24. });
  25.  
  26. var currentParent = $(parent).val();
  27. if (currentParent != 0)
  28. {
  29. DoHillbillyCascade(currentParent,params);
  30. }
  31.  
  32. }
  33.  
  34.  
  35. function DoHillbillyCascade(parentID,params)
  36. {
  37.  
  38. var child = $("select[Title='"+params.childFormField+"'], select[Title='"+
  39. params.childFormField+" Required Field']," +
  40. "select[Title='"+params.childFormField+" possible values']");
  41.  
  42. $(child).empty();
  43.  
  44. var options = "";
  45.  
  46. var call = $.ajax({
  47. url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('"+params.childList+
  48. "')/items?$select=Id,"+params.childLookupField+","+params.parentFieldInChildList+
  49. "/Id&$expand="+params.parentFieldInChildList+"/Id&$filter="+params.parentFieldInChildList+
  50. "/Id eq "+ parentID,
  51. type: "GET",
  52. dataType: "json",
  53. headers: {
  54. Accept: "application/json;odata=verbose"
  55. }
  56.  
  57. });
  58. call.done(function (data,textStatus, jqXHR){
  59.  
  60. for (index in data.d.results)
  61. {
  62. options += "<option value='"+ data.d.results[index].Id +"'>"+
  63. data.d.results[index][params.childLookupField]+"</option>";
  64. }
  65. $(child).append(options);
  66.  
  67. });
  68. call.fail(function (jqXHR,textStatus,errorThrown){
  69. alert("Error retrieving information from list: " + params.childList + jqXHR.responseText);
  70. $(child).append(options);
  71. });
  72.  
  73. }
  74.  
  75. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement