Abort UI Action if field is empty

palmen
Tera Guru

I have a UI Action (form button) which I want to modify.

If you click on it and the field "work_around" is empty I would like a popup that tell the user that "work_around" has to be entered.

If the field "work_around" has any value there should be no popup and the UI Action should be executed.

Any Idea how I could achieve this?

I've tried with the following

Client: True

Action name: post_kb

Onclick: cancelPost

function cancelPost(){

  if (current.work_around == ''){

  alert('MY ALERT MESSAGE.');

  return false;

  }

  //Call the UI Action and skip the 'onclick' function

  gsftSubmit(null, g_form.getFormElement(), 'post_kb'); //MUST call the 'Action name' set in this UI Action

}

Rest of the code for the UI Action goes here....

1 ACCEPTED SOLUTION

arpitt
Tera Expert

Hi Fredrik,



You are using current in client side code that is why it is not working.



Use Below code:



  1. function cancelPost(){  
  2.   if (g_form.getValue('work_around') == ' '){
  3.   g_form.showFieldMsg('work_around','MY ALERT MESSAGE');
  4.   return false;  
  5.   }  
  6.   //Call the UI Action and skip the 'onclick' function  
  7.   gsftSubmit(null, g_form.getFormElement(), 'post_kb'); //MUST call the 'Action name' set in this UI Action  
  8. }  
  9.  
  10. Rest of the code for the UI Action goes here....

View solution in original post

4 REPLIES 4

arpitt
Tera Expert

Hi Fredrik,



You are using current in client side code that is why it is not working.



Use Below code:



  1. function cancelPost(){  
  2.   if (g_form.getValue('work_around') == ' '){
  3.   g_form.showFieldMsg('work_around','MY ALERT MESSAGE');
  4.   return false;  
  5.   }  
  6.   //Call the UI Action and skip the 'onclick' function  
  7.   gsftSubmit(null, g_form.getFormElement(), 'post_kb'); //MUST call the 'Action name' set in this UI Action  
  8. }  
  9.  
  10. Rest of the code for the UI Action goes here....

Thanks!


I still use alert instead of g_form.showFieldMsg, otherwise I won't get the popup and most people seem to not notify the Field Msg.


Masha
Kilo Guru

Look at the OOB UI Action 'Resolve Incident', it does pretty much what you are trying to accomplish here.


My guess is that you code should look something like this:


...


Onclick: cancelPost();



function cancelPost(){


        if(g_form.getValue('work_around') == ''){


                  alert("Your alert message");


                  return false;


        }


//Call the UI Action.....


When looking at our OOB UI Action "Resolve Incident" it has nothing on this in it, maybe because we started on Aspen release?



Only code in the UI Action is


current.state = 6;


current.update();