I'd like to add some custom validation to custom NewForm for external list.
The default new item form has in the ZoneTemplate ListFormWebPart but if i add a new form in SPD2013 there is DataFormWebPart instead of ListFormWebPart in my customNewform.aspx.
My questions are:

  1. Is there any possibility to add another ListFormWebPart for one list?
    • I tried to copy the code of ListFormWebPart from deafult NewForm.aspx and paste it to ZoneTemplate in CustomNewForm.aspx (replace the DataFormWebPart with ListFormWebPart)...but when i saved the changes the form in NewForm.aspx just disappeared and the copied code in CustomNewForm worked perfectly...can anybody explain me this behavior?
  2. I can do some validation for ListFormWebPart when i place the script to PlaceHolderAdditionalPageHead which uses these methods
    • SPClientForms.ClientValidation.ValidationResult
    • RegisterValidator
    • registerClientValidator
    • SPClientTemplates.TemplateManager.RegisterTemplateOverrides

this script works but when i copy it into the customNewForm.aspx (DataFormWebPart) form i got the error like SPClientTemplates is not defined
Do you know any way to write a script which will work with these methods for DataFormWebPart or how to define SPClientTemplates for DataFormWebPart or is it even possible to define?

I have a custom javascript validation for DataFormWebPart using PreSaveAction() function which works as intended but im forced to find some way which will use sharepoint objects and methods...

validation script for ListFormWebPart:

var StreetValidator = function () {
        StreetValidator.prototype.Validate = function (value) {
            var isError = false;
            var errorMessage = "";
            var re = new RegExp('[^ ]+ [0-9\/]+');
            var reTest = re.exec(value);
                errorMessage="Ulica neobsahuje na konci cislo";

            return new SPClientForms.ClientValidation.ValidationResult(isError, errorMessage);

MethodStreetValidate = function (rCtx) {
        if (rCtx == null) return '';

        var formCtx = SPClientTemplates.Utility.GetFormContextForCurrentField(rCtx);

        var validators = new SPClientForms.ClientValidation.ValidatorSet();
        validators.RegisterValidator(new StreetValidator());
        formCtx.registerClientValidator(formCtx.fieldName, validators);

        return SPFieldText_Edit(rCtx); //default renderer for Text field

    (function () {
        var CVOverrides = {};
        CVOverrides.Templates = {};
        CVOverrides.Templates.Fields = {
            'Street': {
                'NewForm': MethodStreetValidate,
                'EditForm': MethodStreetValidate



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.