How can I make the document form field required for users?

I’m having a hard time trying to do this. It seems that it is not an option through the plug-in. The required* settings are only available for metadata properties.

Already fixed with the code below:

function tainacan_document_required() {
    ?>
    <script>
    document.addEventListener("DOMContentLoaded", function () {
        const observer = new MutationObserver(function () {
            const submitBtn = document.getElementById("tainacan-item-submission-block-button--submit");

            if (submitBtn && !submitBtn.dataset.listenerAdded) {
                submitBtn.dataset.listenerAdded = "true";

                submitBtn.addEventListener("click", function (e) {
                    const docSection = document.getElementById("tainacan-item-metadatum_id-document");
                    const uploaded = docSection && (
                        docSection.querySelector(".file-name") ||
                        docSection.querySelector(".tainacan-file-name") ||
                        docSection.querySelector("img") ||
                        docSection.querySelector(".upload-item") ||
                        docSection.querySelector("a")
                    );

                    if (!uploaded) {
                        e.stopImmediatePropagation();
                        alert("Please upload a document before submitting.");
                    }
                }, true);
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    });
    </script>
    <?php
}
add_action('wp_footer', 'tainacan_document_required');

Just put it in the functions.php.

Hi @djafinidad!

This is an interesting request. I’ve opened a new issue for it:

The solution that you offered is a good workaround for the Item Submission Block but I believe we should have it somehow configurable for all item edition forms. We will take a look at this in the future!

1 curtida

Este tópico foi fechado automaticamente 5 dias depois da última resposta. Novas respostas não são mais permitidas.