Jump to content

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.

Link to comment
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);

 

 

Link to comment
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. 

Link to comment
Share on other sites

  • 11 months later...

Here is an interesting thing. I've had a slightly different case.

If you want AT LEASET ONE of the fields to be not zero and only prevent submission when all of them are zero, then you only need to modify one line of the code. Change:
 

if (elements.includes('0')) {

to:

if (elements.every(function(el){
return el == 0})){

 

Link to comment
Share on other sites

  • 2 years later...

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...
×
×
  • Create New...