All posts by Alexander Bautz

Fix classic form fallback on modern lists

ChangeLog

July 31, 2020 – v1.0.0.2

Fixed a bug where only the first 100 DFFS configurations in the SPJS-DynamicFormsForSharePoint list were checked. Also changed a jQspjs (jQuery noConflict namespace in DFFS) reference that made it only work when loaded in a DFFS form and not in a standalone page with plain jQuery loaded.


Microsoft is investigating the ticket i submitted yesterday regarding the breaking change or bug that was released for first release customers on Office 365 – link to my post from yesterday.

In the meantime I have been able to create a script that fixes this problem on all DFFS enabled lists within a site (it must be run once for each site) by writing the NewFormUrl, DispForUrl and EditFormUrl to the content types for these lists. A big thanks to Earl Libby from SPMarketplace for helping me figure out this workaround!

This is what it does

  1. Gets all lists in current site to use in step 2
  2. Gets all stored configurations from the DFFS config list “SPJS-DynamicFormsForSharePoint” and gets all unique lists – finding the list GUID from the lists gathered in step one.
  3. Looping over all content types in all the DFFS enabled lists and checks if the NewFormUrl, DisplayFormUrl and EditFormUrl matches the current content type scope (the current list path) and if not update it.

How to use it

This script is designed to be dropped directly in the console of any page within a SharePoint site, but it needs jQuery to run so it may be best to open a list NewForm by typing in this in the browser address bar:

https://contoso.sharepoint.com/sites/YourSite/Lists/YourList/NewForm.aspx

The open the console and paste the script there.

I recommend using Google Chrome or the new Edge (chromium) as these have better console than Internet Explorer and the old Edge.

The script will log to the console so you know what is going on.

Please note that you need at least manage lists permissions to use this script. Also note that this only fixes lists that already have DFFS installed. This means that any new lists you install DFFS in might still fail unless you re-run this script. This will be fixed when I release a new version of the DFFS installer sometime later this week.

Get the script here

Link to script file (zipped).

Please let me know if you have any question in the comments below.

Best regards,
Alexander

Breaking change / bug in SharePoint Online for first release customers

I have gotten a few reports from users of SharePoint Online that have opted in for “First release”.

When using modern experience for list views and you click New, Open or Edit to add new or view / edit an existing list item, the auto detection of a customized form stopped working.

This customization could be either a web part added to the form (like for DFFS), or a JSLink customization added to a field.

Starting yesterday, instead of falling back to the classic form like it has done for many years, it now shows the default modern form in the slide-out side panel.

I have opened a ticked with Microsoft and have been in contact with them to describe the issue in detail.

At the moment I don’t have any other workaround than to switch back to classic for the affected lists, but I’ll update this post as soon as I know more.

Sorry for the inconvenience,

Alexander

Character or word count in multiline plain text field

June 18, 2020: Updated to fix a bug “countWords”: true.

June 22, 2020: Updated to fix a bug where some of the code was missing in the snippet.

I have updated this old solution to work with DFFS. Please note that it supports multiline PLAIN text fields only – no rich text / HTML.

Add this to your Custom JS:

function counterForMultiLinePlain(arg) {
    jQuery("#dffs_" + arg.fin).find('textarea').bind('keyup blur', function(e) {
        var thisLength = jQuery(this).val().length; // Characters
        var prefix = "";
        if (arg.countWords && thisLength > 0) { // Count words
            thisLength = jQuery(this).val().split(/[' '|\n]/).length;
        }
        // Color code
        if (arg.colorCodeCounter) {
            if ((arg.max > 0 && thisLength >= arg.max) || thisLength < arg.min) {
                jQuery("#myCustomCounter_" + arg.fin).css({
                    'background-color': '#da2931',
                    'font-weight': 'bold',
                    'color': 'white'
                });
            } else if (arg.max > 0 && thisLength > (arg.max - 10)) {
                jQuery("#myCustomCounter_" + arg.fin).css({
                    'background-color': '#FF6600',
                    'font-weight': 'bold',
                    'color': 'white'
                });
            } else {
                jQuery("#myCustomCounter_" + arg.fin).css({
                    'background-color': 'transparent',
                    'font-weight': 'normal',
                    'color': 'black'
                });
            }
        }
        // Min
        var belowMin = false;
        if (arg.min > 0 && thisLength < arg.min) {
            prefix = arg.minLimitLabel.split("{0}").join(arg.min - thisLength);
            belowMin = true;
        }
        // Max
        if (!belowMin && arg.max > 0) {
            prefix = arg.maxLimitLabel;
            if (arg.countWords) { // Count words
                while (thisLength > arg.max) {
                    currVal = jQuery(this).val();
                    jQuery(this).val(currVal.substring(0, currVal.lastIndexOf(' ')));
                    thisLength--;
                }
            } else { // Count characters
                if (thisLength > arg.max) {
                    currVal = jQuery(this).val();
                    jQuery(this).val(currVal.substring(0, arg.max));
                }
            }
            prefix = arg.maxLimitLabel.split("{0}").join(arg.max - thisLength < 0 ? 0 : arg.max - thisLength);
        }
        jQuery("#myCustomCounter_" + arg.fin).html(prefix);
    }).after("<div id='myCustomCounter_" + arg.fin + "' style='padding:2px 4px;margin-top:2px;'></div>").trigger("keyup");
}

// Call the function like this
counterForMultiLinePlain({
    "fin": 'MultilinePlainText',
    "countWords": false,
    "min": 50,
    "max": 0,
    "colorCodeCounter": true,
    "minLimitLabel": "You must add {0} additional characters",
    "maxLimitLabel": "Remaining characters: {0}"
});

Look at the “Call the function like this” section and change the “fin” parameter and adjust the limits and labels – leave min and max as 0 to disable min or max check.

Let me know if you have any questions.

Alexander

I’m opening up for contributors adding their own posts!

I’m now opening up for contributors posting their own DFFS / SharePoint related solutions.

First up is Silvestre Kassoka with a Leave Request System.

Do you want to make a contribution to the community by writing up a posts where you document your solution featuring DFFS or some of my other solutions?

Please email me if this sounds tempting, and I’ll be happy to make you a contributor and let you write up your own story.

I hope to hear from you soon!

Best regards,
Alexander