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