0

I need please help by my JS Link problem. I want to lock a column in a form when it has a value inside. To do this I try this code. It works but when I click on save the value in the title filed will not be saved.

This is the code I used var _TitleField = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx); var _TitleFieldId = _TitleField.fieldSchema.Id; var _TitleFieldName = _TitleField.fieldName; var _TitleFieldValue = ctx.CurrentItem.Title;

var _TitleFieldDiv = _TitleFieldName + '_' + _TitleFieldId + '_$TextField';

var result = "";


if (_TitleFieldValue) {
result = "<div><input type='text' id='" + _TitleFieldId + "' name= '" + _TitleFieldName + "' value= '" + _TitleFieldValue +  "'disabled='disabled' /></div>";
} else {
result = "<div id='" + _TitleFieldDiv + "'><input type='text' id='" + _TitleFieldId + "' title= '" + _TitleFieldName + "' value='' maxlength='255' class='ms-long ms-spellcheck-true'></div>";  
};

return result;

Thanks for your help

4

Stefan, you need to register callbacks so that SharePoint will call them at appropriate times. In this case while saving the item.

formCtx.registerGetValueCallback(formCtx.fieldName, function () { })

In the above function you got to return your fieldvalue so that sharepoint will pick it while saving the item.

Please let me know if you have any questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.