Jump to content
  • 0

Update Form: Limit User's Number of Selections in a Field with List - String Datatype


wimtracking2

Question

5 answers to this question

Recommended Posts

  • 0

Hello @wimtracking2,

The easiest way is to restrict submitting the form when more than 8 values in the List-String field were selected.

As far as I understand, you are referring to the Single Record Update form.

I tested this code and it works for me:

<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
document.addEventListener("BeforeFormSubmit", function (event) {
  const listOfvalues = document.querySelector('input[name="EditRecordlist"]').value;  // replace the 'list' part with your field name
  const numberOfValues = listOfvalues.split(",").length;

  if (numberOfValues > 8) {
    event.preventDefault();

    Swal.fire({
      icon: "warning",
      title: "Select less than 8 values",
    });
  }
});
</script>

You may paste the code to the Footer section and disable the HTML editor before pasting.

I am using so-called SweetAlert (https://sweetalert2.github.io/) to display a warning and the first line of code and Swal.fire() refers to it.

Edited by CoopperBackpack
Changed the selector for the listOfvalues variable, so it works for Multiselect Dropdown and Multiselect Listbox
Link to comment
Share on other sites

  • 0
On 12/8/2021 at 9:42 AM, CoopperBackpack said:

Hello @wimtracking2,

The easiest way is to restrict submitting the form when more than 8 values in the List-String field were selected.

As far as I understand, you are referring to the Single Record Update form.

I tested this code and it works for me:

<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
document.addEventListener("BeforeFormSubmit", function (event) {
  const listOfvalues = document.querySelector('input[id^="EditRecordlist"]').value; // replace the 'list' part with your field name
  const numberOfValues = listOfvalues.split(",").length;

  if (numberOfValues > 8) {
    event.preventDefault();

    Swal.fire({
      icon: "warning",
      title: "Select less than 8 values",
    });
  }
});
</script>

You may paste the code to the Footer section and disable the HTML editor before pasting.

I am using so-called SweetAlert (https://sweetalert2.github.io/) to display a warning and the first line of code and Swal.fire() refers to it.

This is exactly what I needed and it worked perfectly, thank you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...