0

I'm working on JSF, I'm unable to make action call after JavaScript (JS) execution. Without JS action is getting executed as expected. What is needed: Disable the command button until the action (submit) is performed. Below is the reference piece of code that i'm using.

<h:commandButton id = "search" value="Submit" action="#{ManagedBean.retrieve}"           
    onclick="return buttonDisable();" />

<script type="text/javascript">
        function buttonDisable() {
            document.getElementById('editForm:search').click();
            document.getElementById('editForm:search').disabled = true;
            document.getElementById('editForm:search').style.backgroundColor="#cccccc";
            return true;
        }
</script>

Tried many ways but could not find a solution yet. Your suggestions are much appreciated.

Andrew
  • 373
  • 2
  • 15
Amulya
  • 3
  • 2

1 Answers1

0

If you change "document.getElementById('editForm:search').disabled = true;" to disabled = false, does that work?

That way after the click it won't be disabled.

Justin Feakes
  • 380
  • 1
  • 7
  • Thank you for your suggestion Justin. Actually the requirement is the buttons should be disabled till the action is completed. Sorry if i was not clear before. – Amulya Nov 13 '19 at 09:02
  • @Amulya That was not the question... Did you TRY... If so you have way more info on what is the cause of the issue. Please try... – Kukeltje Nov 13 '19 at 10:12
  • @Kukeltje, I have tried with disabled=false, But now the button looks like its disabled but i'm still able to perform submit. Am i missing something? – Amulya Nov 13 '19 at 14:17
  • Dears, I have used below function to set the timeout in JS. This would allow action to execute before disabling the button. Below solution worked for me. – Amulya Nov 14 '19 at 06:49