Search code examples
javahtmlmvvmzkzul

How to unselect a radio button in zk when no radioGroup is used


Let say we have this code:

<window>    
   <radio selected="@bind(vm.value)" /> 
</window>

When we click this radio button it will get selected ...but clicking it again do not unselect it..

Is there a better approach other then binding the onClick and toggling it in java ?


Solution

  • Try it :

    you create a method in java class just like showVisibleRadio and check condition .

       <window>    
           <radio selected="@bind(vm.value)"   onCheck="@command('showVisibleRadio')"/> 
        </window>  
    

    //java code

      @Command
         public void  showVisibleRadio(){
    
           if (value.isChecked()){
           value.setChecked(false);
           }
           else{
           value.setChecked(true);
          }
        }