I have the following custom field renderer:
'renderInitials': function (field, value) { value = skuid.utils.decodeHTML(value);<br>var nurseModel = skuid.$M('Nurses');<br>if (!nurseModel) {<br>var runCreateNurseModel = skuid.snippet.getSnippet('createNurseModel');<br>nurseModel = runCreateNurseModel();<br>}<br>if (field.mode === 'edit'){<br> var initials = [],<br> currentRN = value,<br> renderer = false,<br> userId = skuid.utils.userInfo.userId;<br> <br> //get options for initials picklist <br> <b>$.each(nurseModel.getRows()</b>, function(i, row){<br> initials.push({<br> value: row.Initials__c,<br> label: row.Initials__c<br> });<br> if (!currentRN && (row.Id == userId)) {currentRN = row.Initials__c}<br> });<br> <br> //determine if we should set the default initials<br> switch (field.id) {<br> case 'RN_Initials_for_Test__c' :<br> renderer = (field.model.getFieldValue(field.row, 'STD_Test_Method__c')) ? true : false;<br> break;<br> case 'RN_Initials_for_Results__c' :<br> renderer = (field.model.getFieldValue(field.row, 'Results__c')) ? true : false;<br> break;<br> case 'RN_Initials_for_Reporting_to_Patient__c' :<br> renderer = (field.model.getFieldValue(field.row, 'Results_Reported_to_Patient__c')) ? true : false;<br> break;<br> case 'RN_Initials_Reporting_to_Health_Dept__c' :<br> renderer = (field.model.getFieldValue(field.row, 'Results_Reported_to_Health_Department__c')) ? true : false;<br> break;<br> case 'RN_Initials_for_Treatment__c' :<br> renderer = (field.model.getFieldValue(field.row, 'STD_Treatment__c')) ? true : false;<br> break;<br> }<br> <br> //render picklist<br> var customSelect = skuid.ui.renderers.PICKLIST.edit({<br> entries : initials,<br> required : false,<br> defaultValue : (renderer) ? currentRN : ''<br> }).change(function() {<br> // Update the row in the target object<br> field.model.updateRow(field.row, field.id, $(this).val());<br> });<br> field.element.append(customSelect);<br>} else {<br> skuid.ui.fieldRenderers.TEXT[field.mode](field,value);<br>}<br>}
If the ‘Nurses’ model doesn’t exist, I’m running this createNurseModel snippet to create it:
'createNurseModel': function() { <br>// Create dynamic model to capture nurse<br>nurseModel = new skuid.model.Model();<br>nurseModel.objectName = 'User';<br>nurseModel.id = 'Nurses';<br>nurseModel.fields = .<br> { id: 'Id' },<br> { id: 'Initials__c' }<br>];<br>nurseModel.orderByClause = 'Initials__c'<br>nurseModel.conditions = d<br> { <br> type: 'fieldvalue', <br> field: 'UserRole.Name', <br> operator: 'contains', <br> value: 'RN',<br> enclosevalueinquotes: true<br> }<br>];<br>nurseModel.initialize();<br>$.when(nurseModel.load())<br>.then(function(){<br>return nurseModel;<br>});<br>}
However, I’m getting the error that nurseModel is undefined when the field renderer tries to call getRows() on it in the $.each() in bold.
Is there something I’m missing here? Do I have to somehow get the field renderer snippet to wait until the createNurseModel snippet actually returns a model? And if so, how can I do that? Can I somehow return both a jQuery deferred promise and a model in the return statement after I create the model?