(function () {
// Create object that have the context information about the field that we want to change it's output render
var ageFiledContext = {};
ageFiledContext.Templates = {};
ageFiledContext.Templates.Fields = {
// Apply the new rendering for Age field on New and Edit forms
"Age": {"NewForm": ageFiledTemplate,"EditForm": ageFiledTemplate
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ageFiledContext);
})();
function getListItems(){
var OptionHTMLText="";
}
// This function provides the rendering logic
function ageFiledTemplate(ctx) {
var OptionHTMLText= getListItems()
var formCtx = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
// Register a callback just before submit.
formCtx.registerGetValueCallback(formCtx.fieldName, function () {
return document.getElementById('inpAge').value;
});
var clientContext = SP.ClientContext.get_current();
var getLists = clientContext.get_web().get_lists();
var listName="Master List";
var spList = getLists.getByTitle(listName);
var query = new SP.CamlQuery();
query.set_viewXml('<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>');
var spItems = spList.getItems(query);
clientContext.load(spItems);
clientContext.executeQueryAsync(function () {
var enumerator = spItems.getEnumerator();
while (enumerator.moveNext()) {
var currentListItem = enumerator.get_current();
var titlevalue=currentListItem.get_item("Title");
OptionHTMLText+='<option value="'+titlevalue+'">'+titlevalue+'</option>'
}
return '<select id="inpAge">'+OptionHTMLText+'</select>'
},function(){
alert("Error getting list items");
});
//return '<select id="inpAge"><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="opel">Opel</option><option value="audi">Audi</option></select>'
}please find my JS link code:
i am converting text box field age into dropdown and loading dropdown values from other list
problem is executequery block works after completing ageFiledTemplate end statement so not able to load dropdown dynamic data