Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enable\Disable commandButton in javascript with angular and jquery checking hidden field value  RSS feed

 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all.

I have a simple form with a commandbutton and an inputhidden:


After that code there is a data grid builded and managed by angular with many records.
The button btnStampaModAgenti must be disabled if there are no record selected or more than one record selected

In javascript :


It works: when i select a row, the button is enabled, when i select 0 or >1 rows, the button is disabled and i can't click it.
The hidden field is used to pass the "javascript" selected element in the request.

But at page loading, the button is showed ad enabled even if there are no rows selected.
If i put disabled="true" in the command button, no action will be executed.


There isn't a more simple way to disable/enable in javascript a command button checking if an inputhidden field value is empty?
 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inserted


before </h:form>

Now it work.

Does exist a more simple and fancy way to do the same thing?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: action="#{stampe.moduliAgente()}" is bad practice. Actions should be method references, not method calls. So "action="#{stampe.moduliAgente}"

You can experience problems when using JavaScript to modify the attributes of JSF controls because JSF generates context based on what the server knows about the control's state, not on what the client is doing to it.

A more reliable approach is to use AJAX. The action method can then set a backing bean boolean property that can be referenced in JSF EL on the control's "enabled" attribute.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!