Caspio101 Posted January 24, 2020 Report Share Posted January 24, 2020 I have a submission form with a couple of calculated values; need to disable submit button if either of those values are zero. Any help to achieve that functionality is appreciated researched 1 Quote Link to comment Share on other sites More sharing options...
Hastur Posted January 28, 2020 Report Share Posted January 28, 2020 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. Vitalikssssss and researched 1 1 Quote Link to comment Share on other sites More sharing options...
Caspio101 Posted January 29, 2020 Author Report Share Posted January 29, 2020 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); researched 1 Quote Link to comment Share on other sites More sharing options...
kpcollier Posted January 29, 2020 Report Share Posted January 29, 2020 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. researched 1 Quote Link to comment Share on other sites More sharing options...
Caspio101 Posted January 30, 2020 Author Report Share Posted January 30, 2020 Wonderful! It worked! Deeply appreciate your inputs, @Hastur and @kpcollier researched 1 Quote Link to comment Share on other sites More sharing options...
Caspio101 Posted February 6, 2020 Author Report Share Posted February 6, 2020 @kpcollier or @Hastur, are you able to help me with a related question please? If I need to check a field for blanks and then disable, can I check against '' in element.includes(), instead of 0? (elements.includes('') researched 1 Quote Link to comment Share on other sites More sharing options...
Hastur Posted February 11, 2020 Report Share Posted February 11, 2020 @Caspio101 It is better to check it in such a manner: if (strValue === "") { //... } OR if (strValue) { //... } researched 1 Quote Link to comment Share on other sites More sharing options...
FaeFaeFae Posted February 8, 2021 Report Share Posted February 8, 2021 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})){ researched 1 Quote Link to comment Share on other sites More sharing options...
IamNatoyThatLovesYou Posted May 20, 2023 Report Share Posted May 20, 2023 Hello Everyone, you can also check this forum post that hides the submit button once it has been clicked/pressed. researched 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.