1

I have build some scripts running in the PreSaveAction function for example to validate some data or conditionaly send an email via ajax call. Now I need this functionality when the user creates a new item or edit an item through quick edit mode. Is there something equivalent to that function or does anyone know how to solve this issue? After long time of searching maybe I could find some help here and don't need to do it with an event receiver. Thx

//https://www.spjeff.com/2014/05/17/quick-edit-supports-js-link-and-client-side-rendering/
(function () {
    var overrideContext= {};
    overrideContext.Templates = {};
    overrideContext.Templates.Fields = {
        "Module": {
            "View": setDefaultValue
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
})();
function setDefaultValue(ctx) {
    var formCtx = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    var validators = new SPClientForms.ClientValidation.ValidatorSet(); 
    if(ctx.CurrentItem.Module != ""){
        if(ctx.CurrentItem.Module[0].lookupValue != 'Aussenanlage'){
                ret = "<div style='color: white; background-color: lightgreen'>"
        + " <img src='http://sharepoint.***/_layouts/15/images/kpinormal-0.gif' /> " 
        + ctx.CurrentItem.Module[0].lookupValue;
        + "</div>";
        }
        else {
                ret = "<div style='color: black; background-color: yellow'>"
        + " <img src='http://sharepoint.***/_layouts/15/images/kpinormal-0.gif' /> " 
        + ctx.CurrentItem.Module[0].lookupValue;
        + "</div>";     
        }               
    }
    else {
        ret = "";
    }   
    return ret;
}
2

I think you can try to use CSR (client side rendering) for validation purposes and workflows for email sending.
CSR like here:
https://sii.pl/blog/client-side-rendering-in-sharepoint/
https://julieturner.net/2015/08/jslink-validation-from-basic-to-advanced/
https://msdn.microsoft.com/en-US/magazine/dn745867.aspx
https://www.softlanding.ca/about-Softlanding/resources/blog/field-validation-client-side-rendering
Search "RegisterValidator" in text of this articles.
May be it is applicable to Quick Edit view.

UPDATED:

Yes, you can use CSR for validation in Quick Edit mode and to change your cell (column row intercept) control to some new control with new features. But I doesn't have fully completed code for that.
At these links I found ways to change quick edit column control to other and set validation to them. 1, 2, 3.
You can create code like below. Warning - it is not competed to correctly validate your field. It is my code, I tested it, it is working, but not completed:

<script type="text/javascript">
// https://chuvash.eu/2014/11/27/jsgrid-basics/
// http://sharepointbitsandbytes.com/2014/01/sharepoint-2013-quick-edit-javascript-validation/
// https://stackoverflow.com/a/48588562/10745346
var QuickEditTestNamespace = QuickEditTestNamespace || {};
QuickEditTestNamespace.IsContolValueValid = function (value) {
    // TODO: custom validation logic
    var isContolValueValid = !!value && value === 'MyValidValue';
    return isContolValueValid;
};
QuickEditTestNamespace.handleGridMode = function (ctx, field) {
    var currentFieldSchema = ctx.CurrentFieldSchema;
    SP.SOD.executeOrDelayUntilScriptLoaded(function () {
        SP.GanttControl.WaitForGanttCreation(function (ganttChart) {
            var targetColumn = null;
            var editId = "EDIT_CONTROL_ADVANCED_" + currentFieldSchema.Name.toUpperCase();
            var columns = ganttChart.get_Columns();

            for (var i = 0; i < columns.length; i++) {
                if (columns[i].columnKey == currentFieldSchema.RealFieldName) {
                    targetColumn = columns[i];
                    break;
                }
            }
            if (targetColumn) {

                targetColumn.fnGetEditControlName = function (record, fieldKey) {
                    return editId;
                };
                SP.JsGrid.PropertyType.Utils.RegisterEditControl(editId, function (gridContext, cellControl) {

                        var newEditControl = new SP.JsGrid.EditControl.EditBoxEditControl(gridContext, null);

                        newEditControl.SetValue = function (value) {
                            debugger;
                            var _cellContext = newEditControl.GetCellContext();
                            newEditControl._cellContext = _cellContext;

                            var isContolValueValid = QuickEditTestNamespace.IsContolValueValid(value);
                            if (isContolValueValid == true) {
                                _cellContext.SetCurrentValue({ localized: value });
                            } else {
                                gridContext.jsGridObj.SetCellError(_cellContext.record.recordKey, currentFieldSchema.RealFieldName, "Your field is INVALID!");
                            }
                        };

                        newEditControl.Unbind = function () {
                            debugger;
                            _cellContext = newEditControl._cellContext;

                            if (_cellContext != null) {
                                gridContext.jsGridObj.ClearAllErrorsOnCell(_cellContext.record.recordKey, currentFieldSchema.RealFieldName);
                            }
                        };

                        return newEditControl;

                }, []);
            }

        });
    }, "spgantt.js");
};
QuickEditTestNamespace.fieldProcessor = function (ctx, field) {
    var fieldValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 
    if (ctx.inGridMode) {
        QuickEditTestNamespace.handleGridMode(ctx, field);
    }
    return fieldValue;
};
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    var overrideContext = {}; 
    overrideContext.Templates = {}; 
    overrideContext.Templates.Fields = { 
        "LinkTitle": { 
            "View": QuickEditTestNamespace.fieldProcessor 
        } 
    }; 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
});
</script>

I don't want to investigate this case to fully completed code but If you have time then you can try. It must worked correctly but I don't know how much time you will spend on this task and may be some bugs exists in this logic =) . May be you will spend one week or more.

  • 1
    This "RegisterValidator" topic could be a solution. I'll give it a try. thx. – lex Dec 10 '18 at 19:27
  • Hey Vsevolod, thank you for your links. In my case I couldn't find a solution, because the FormContext is always null. I think it's because of the Quick Edit Mode. I found an article: sharepointbitsandbytes.com/2014/01/… that can help (maybe). If not I'll solve it by using Remote Event Receiver... my already existing scripts for the new- and edit form than can't be used anymore. – lex Dec 11 '18 at 9:52
  • Can you add your code with FormContext null to your question ? I will try to reproduce later. – user80188 Dec 11 '18 at 11:24
  • Hi Vsevolod, first thx again. I've added the code that I used just for trial and error and to determine how it works. Now I decided to write a Remote Event Receiver. It's going well and is working in quick edit mode too. So, just do it if you are also interested in a client side solution. I would still appreciate. – lex Dec 11 '18 at 15:26
  • OK. Just for you to know. formCtx is null and SPClientForms can not be found. I think, because it's a view context and not form. – lex Dec 11 '18 at 15:34

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.