javascriptsharepointjslink

JS field rendering return standard field rendering


how can return the standard rendering of a field?

(function () {

    var readonlyFiledContext = {};
    readonlyFiledContext.Templates = {};
    readonlyFiledContext.Templates.Fields = {
        // Apply the new rendering for Age field on Edit forms
        "Title": {
            "EditForm": FieldTemplate
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(FiledContext);

})();

function FieldTemplate(ctx) {

     return ;
    }
}

It depends on the value I like to render the filed. When the value is not null then make it fancy and when it is equals “null” then render like the standard rendering. How I can in this code segment return the standard field rendering?

Thanks for help Stefan


Solution

  • The following example demonstrates how to render text field using default rendering template if value is not empty:

    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    
    
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
    
          Templates: {
    
               Fields: {
                   "ReqNo": {
                       EditForm: renderRegNo,
                   }
               }
          }
    
        });
    
    });
    
    function renderRegNo(ctx){
      if(ctx.CurrentItem.RegNo.length == 0) {
           return "Request number is missing";
      }
      return SPFieldText_Edit(cxt); 
    }
    

    Note: it is assumed that the RegNo field is of Text type


    clientforms.js contains the list of default field rendering templates (per field type):

    var spfieldCtx = {
                Templates: {
                    Fields: {
                        'Text': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPFieldText_Edit,
                            'NewForm': SPFieldText_Edit
                        },
                        'Number': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPFieldNumber_Edit,
                            'NewForm': SPFieldNumber_Edit
                        },
                        'Integer': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPFieldNumber_Edit,
                            'NewForm': SPFieldNumber_Edit
                        },
                        'Boolean': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_DefaultNoEncode,
                            'EditForm': SPFieldBoolean_Edit,
                            'NewForm': SPFieldBoolean_Edit
                        },
                        'Note': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldNote_Display,
                            'EditForm': SPFieldNote_Edit,
                            'NewForm': SPFieldNote_Edit
                        },
                        'Currency': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPFieldNumber_Edit,
                            'NewForm': SPFieldNumber_Edit
                        },
                        'File': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldFile_Display,
                            'EditForm': SPFieldFile_Edit,
                            'NewForm': SPFieldFile_Edit
                        },
                        'Calculated': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPField_FormDisplay_Empty,
                            'NewForm': SPField_FormDisplay_Empty
                        },
                        'Choice': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPFieldChoice_Edit,
                            'NewForm': SPFieldChoice_Edit
                        },
                        'MultiChoice': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPFieldMultiChoice_Edit,
                            'NewForm': SPFieldMultiChoice_Edit
                        },
                        'Lookup': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldLookup_Display,
                            'EditForm': SPFieldLookup_Edit,
                            'NewForm': SPFieldLookup_Edit
                        },
                        'LookupMulti': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldLookup_Display,
                            'EditForm': SPFieldLookup_Edit,
                            'NewForm': SPFieldLookup_Edit
                        },
                        'Computed': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPField_FormDisplay_Default,
                            'EditForm': SPField_FormDisplay_Default,
                            'NewForm': SPField_FormDisplay_Default
                        },
                        'URL': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldUrl_Display,
                            'EditForm': SPFieldUrl_Edit,
                            'NewForm': SPFieldUrl_Edit
                        },
                        'User': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldUser_Display,
                            'EditForm': SPClientPeoplePickerCSRTemplate,
                            'NewForm': SPClientPeoplePickerCSRTemplate
                        },
                        'UserMulti': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldUserMulti_Display,
                            'EditForm': SPClientPeoplePickerCSRTemplate,
                            'NewForm': SPClientPeoplePickerCSRTemplate
                        },
                        'DateTime': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldDateTime_Display,
                            'EditForm': SPFieldDateTime_Edit,
                            'NewForm': SPFieldDateTime_Edit
                        },
                        'Attachments': {
                            'View': RenderFieldValueDefault,
                            'DisplayForm': SPFieldAttachments_Default,
                            'EditForm': SPFieldAttachments_Default,
                            'NewForm': SPFieldAttachments_Default
                        }
                    }
                }
            };