Enable and disable button base on state

adityamadhira
Kilo Contributor

I need onchange client script to enable /disable button based on state.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  // var state = g_form.getValue('state');

if(newValue== 11 ){

    var items = $$('BUTTON').each(function(item){

    if(item.innerHTML.indexOf('Submit') > -1){

          item.hide();  

    }

});

  }

else{

var _items = $$('BUTTON').each(function(item){

    item.innerHTML.indexOf('Submit').show();  

   

});

}

}

It fails the behavior.

Thanks

1 ACCEPTED SOLUTION

I didnt realize your show logic is flawed...


function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


  // var state = g_form.getValue('state');  


if(newValue== 11 ){  


  var item = $$('BUTTON').each(function(item){  


  if(item.innerHTML.indexOf('Submit') > -1){  


          item.hide();  


  }  


});  


  }  


else{  


var _item = $$('BUTTON').each(function(_item){  


  if(_item.innerHTML.indexOf('Submit') > -1){  


          _item.show();  


  }  


});  


}  


}


View solution in original post

22 REPLIES 22

Create a button on the table with the same action name. It will override the global one.


Kalai,


Thanks, it worked. I made the name and action name of the UI Action same as the global one, and it just worked. is this a good practice to keep the same action name, no violations?


Yes. It is preferred when compared to editing global button


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  // var state = g_form.getValue('state');


if(newValue== 11 ){


  var item = $$('BUTTON').each(function(item){


  if(item.innerHTML.indexOf('Submit') > -1){


          item.hide();


  }


});


  }


else{


var _item = $$('BUTTON').each(function(_item){


  _item.innerHTML.indexOf('Submit').show();



});


}


}


It fails to show back the hide button.