Date <= Today

Home Forums Classic DFFS Date <= Today

Viewing 3 reply threads
  • Author
    Posts
    • #32241
      Oranges2
      Participant

        Hi. I have a date field where I would like to require that users select a date that is less than or equal to today. Is this possible?

        I am using Dynamic Forms for SharePoint v4.4.5.13

        Thank you.

      • #32243
        Alexander Bautz
        Keymaster

          Hi,
          You can set up a rule on your date field with the operator “greater than” and value [today]. Also set the Save item button visiblity = Hidden.

          This way the save button is not visible if the user haven’t selected the proper date value.

          There are other options using Custom JS also, but try this one first.

          Alexander

        • #32245
          Oranges2
          Participant

            Thank you. The [today] piece worked great for the expression. I tried setting the save button to not be visible but a couple things happen:

            – If the date is entered in the future, and then changed to be in the past, the save button is visible again BUT it is grayed out/disabled.
            – The save button in the ribbon is still visible and when clicked, the behavior now downloads the document instead of saving the item.
            – Since it’s not checking the date field until after you exit the field, this could also be an issue for what I’m trying to do since they could enter the date and click Save right away.

            I tried this on Edge, Chrome and Internet Explorer with the same results.

          • #32247
            Alexander Bautz
            Keymaster

              I did a quick test and noticed a bug with hiding the save button in the ribbon in a document library – not sure if this is something new in SPO or a bug that has slipped past me for a long time, but I’ll get this fixed in the next release.

              I’m not able to reproduce the disabled button, but the download of the document is caused by NOT having the a “RootFolder” or “Source” parameter in the URL query string. If you exit directly from the DFFS configuration to EditForm you might get this behavior.

              Clicking directly from the datepicker to the save button should not let the user save, but you can try using this Custom JS approach instead (remove the rules – this only uses custom js).

              function dffs_PreSaveAction() {
                  var date = spjs.utility.getDateFieldAsDateObject("DateField");
                  date.setHours(12, 0, 0, 0);
                  var today = new Date();
                  today.setHours(12, 0, 0, 0);
                  if (date > today) {
                      spjs.modal.add({
                          "title": "Wrong date selected",
                          "html": "You must select a date that is less than or equal to today.",
                          "allowMaximize": false,
                          "resizable": false,
                          "ok": function() {
                              // Close dlg
                          }
                      });
                      return false;
                  }
                  return true;
              }

              Replace “DateField” with your date picker internal name.

              Alexander

          Viewing 3 reply threads
          • You must be logged in to reply to this topic.