Repository: jenkinsci/jenkins
File: src/main/js/add-item.js (JavaScript)

Code before:
    function setFieldValidationStatus(fieldId, status) {
      document.querySelector("#" + fieldId).dataset.valid = status;
    }

    function activateValidationMessage(messageId, context, message) {
      if (message !== undefined && message !== "") {
        document.querySelector(context + " " + messageId).textContent =
          "» " + message;
      }
      cleanValidationMessages(context);
      document
        .querySelector(messageId)
        .classList.remove("input-message-disabled");
      refreshSubmitButtonState();
    }

    function cleanValidationMessages(context) {
      document
        .querySelectorAll(context + " .input-validation-message")
        .forEach((element) => element.classList.add("input-message-disabled"));
    }

    function refreshSubmitButtonState() {
      const submitButton = document.querySelector(
        ".bottom-sticker-inner button[type=submit]",
      );
      submitButton.disabled = !getFormValidationStatus();
    }

    function getFormValidationStatus() {
      if (
        getFieldValidationStatus("name") &&
        (getFieldValidationStatus("items") || getFieldValidationStatus("from"))
      ) {
        return true;
      }
      return false;
    }

    function cleanItemSelection() {
      document
        .querySelector('.categories li[role="radio"]')
        .setAttribute("aria-checked", "false");
      document
        .querySelector('#createItem input[type="radio"][name="mode"]')
        .removeAttribute("checked");
      document.querySelectorAll(".categories .active").forEach((item) => {
        item.classList.remove("active");
      });
      setFieldValidationStatus("items", false);
    }

Review comment (suggestion):
Rather than accept a true/false parameter lets just have the function handle whether the button should be valid or not.

Code after:
    function setFieldValidationStatus(fieldId, status) {
      const element = document.querySelector("#" + fieldId);
      if (element) {
        element.dataset.valid = status;
      }
    }

    function activateValidationMessage(messageId, context, message) {
      if (message !== undefined && message !== "") {
        document.querySelector(context + " " + messageId).textContent =
          "» " + message;
      }
      cleanValidationMessages(context);
      document
        .querySelector(messageId)
        .classList.remove("input-message-disabled");
      refreshSubmitButtonState();
    }

    function cleanValidationMessages(context) {
      document
        .querySelectorAll(context + " .input-validation-message")
        .forEach((element) => element.classList.add("input-message-disabled"));
    }

    function refreshSubmitButtonState() {
      const submitButton = document.querySelector(
        ".bottom-sticker-inner button[type=submit]",
      );
      submitButton.disabled = !getFormValidationStatus();
    }

    function getFormValidationStatus() {
      if (
        getFieldValidationStatus("name") &&
        (getFieldValidationStatus("items") || getFieldValidationStatus("from"))
      ) {
        return true;
      }
      return false;
    }

    function cleanItemSelection() {
      document
        .querySelector('.categories li[role="radio"]')
        .setAttribute("aria-checked", "false");
      document
        .querySelector('#createItem input[type="radio"][name="mode"]')
        .removeAttribute("checked");
      document.querySelectorAll(".categories .active").forEach((item) => {
        item.classList.remove("active");