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

Kalaiarasan Pus
Giga Sage

Just a question.


Why do you need to hide it using a onchange script ? Can't you make use of condition field in UI action and show/hide it ?


Here hiding is based on state(choice list). UI action will hide permanently.


So it's like once the state is changed, button should not be available. How is that different from using the condition field?


Logically speaking, if you change the state on the form, that doesn't mean the state of the ticket is changed at the table/database level. Are you sure of the requirement that you need to hide the button on onchange of state and not the actual change of state?



I would recommend you to clarify this before you start implementing. Frankly speaking, these custom scripts will give you more headache's during instance upgrades. I would not go this route unless it is absolutely necessary and clients are not agreeing


Is there any other way.



My requirement - Add new field "InQueue" to state choice list for change ticket.



When user select InQueue -- Form button must be disappear so that the change ticket will not move forward.


if they select other state - change ticket will move forward.



I tried UI Action --> but it want reflect when we change choice list.


Hello Kalairasan,



Have a question around the same hide/show button. I have a requirement where in I have to implement a custom Submit button (Got to implement a custom client script specific to my change request form), but the out of the box global 'Submit' button is also getting displayed on the change form in addition to the custom Submit UI action I just created. Do you recommend an alternative solution to get rid of the out of the box 'Submit' buttom than the below piece of onload() script to hide the button?