Jump to content
Sign in to follow this  
Caspio101

Disable Submit button

Recommended Posts

Hi @Caspio101

You can implement this workflow using the JS code.
Here is the code with comments on parts which needs to be changed according to your workflow:

<style>
    /* some styles for the disabled button */
    input[name="Submit"]:disabled {
        cursor: not-allowed !important;
        background-color: gray !important;
    }
</style>

<script type="text/javascript">

    function inputHandler(event, elementsSelectors) {
        if (!!event.target.innerHTML.trim()) {
            let elements = elementsSelectors.map( function(selector) {
                return document.querySelector(selector).innerHTML.trim()
            });
            if (elements.includes('0')) { // Here you may change the condition. Now the button will be disabled if at least one calc value is equal to 0
                document.querySelector('input[name="Submit"]').disabled = true;
            } else {
                document.querySelector('input[name="Submit"]').disabled = false;
            }
        } else {
            return null;
        }
    }


    function assignEvent() {
      	// here you may define the list of the selectors to choose calculated fields you may use in condition
        let elementsSelectors = ['span[id^="InsertRecordfield_1"]', 'span[id^="InsertRecordfield_2"]', 'span[id^="InsertRecordfield_3"]'];

        elementsSelectors.forEach(function(selector)  {
            document.querySelector(selector).addEventListener('DOMSubtreeModified', function() { 
                 inputHandler(event, elementsSelectors);
            });
        });
        document.removeEventListener('DataPageReady', assignEvent);
    }

    document.addEventListener('DataPageReady', assignEvent);
</script>

 

You need to insert this code into the header of the submission form. Do not forget to disable the HTML editor in the advanced section of the header.

Share this post


Link to post
Share on other sites

Thank you, I am completely novice to JS and front end development in general; so please bear with me for very fundamental questions.

Do I need to replace InsertRecordfield_1 with my calculated field name such as Virtual 1 or Virtual2? Or are there specific ids for the value placeholders that I need to use?

// here you may define the list of the selectors to choose calculated fields you may use in condition
        let elementsSelectors = ['span[id^="InsertRecordfield_1"]', 'span[id^="InsertRecordfield_2"]', 'span[id^="InsertRecordfield_3"]'];

        elementsSelectors.map(function(selector)  {
            document.querySelector(selector).addEventListener('DOMSubtreeModified', function() { 
                 inputHandler(event, elementsSelectors);

 

 

Share this post


Link to post
Share on other sites
3 hours ago, Caspio101 said:

Do I need to replace InsertRecordfield_1 with my calculated field name such as Virtual 1 or Virtual2? Or are there specific ids for the value placeholders that I need to use?

If you are using a Submission or Single Update form, you need to use 'InsertRecord______' where you would put the table name of the field in the blank space. If you are working on any report datapage, you need to make it 'EditRecord______' with the field name of the field in the blank. In example, if your field name was 'First_Name' and it was a sub form, you would use 'InsertRecordFirst_Name'.

However, if the field you are using is a virtual parameter, you would use 'cbParamVirtual#' where you would put the Virtual Field number instead of the '#'. So, if your field was Virtual13, you would use 'cbParamVirtual13'. With virtual fields, you do not need to use 'EditRecord' or 'InsertRecord' no matter what page you are using it on. 

Share this post


Link to post
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
Reply to this topic...

×   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...
Sign in to follow this  

×
×
  • Create New...