質問

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;
}
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top