How to restrict a form to be submitted in JavaScript?

Mohd Shahnawaz
Tera Contributor

How to restrict a form to be submitted in JavaScript?

1 ACCEPTED SOLUTION

Gowrisankar Sat
Tera Guru

You can restrict the form submission, through onSubmit Client Scripts/ Business Rules.



onSubmit client scripts:



  1. function onSubmit() {      
  2.   if(g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'YESb' && g_form.getValue('question_choice') == 'incorrect info' ) //assuming values are YES and YESb    
  3.   {      
  4.             if(g_form.getValue('user_confirm') == 'false' ){      
  5.                   var result = confirm('Are you sure you wish to submit?');//or whatever that checkbox is for  
  6.                   if (result) {  
  7.                             g_form.setValue('checkbox', true);  
  8.                   else  
  9.                           return false;   //Here return false will stop the submission of the form.
  10.             }      
  11.   }      
  12. }    


Business Rules:



  1. (function executeRule(current, previous /*null when async*/) {  
  2. ....    
  3.   if (<condition to prevent delete>) {  
  4.   gs.addErrorMessage(gs.getMessage("You cannot delete a task where users have logged time against the task."));  
  5.   current.setAbortAction(true);     //setAbortAction will prevent the data to be inserted/updated
  6.   }  
  7. })(current, previous);

View solution in original post

2 REPLIES 2

Siddartha Gudim
Tera Guru

Use can make use of onsubmit client script on the form to restrict for subitting


EG:



function onSubmit() {


alert(g_form.getValue('ad_domain')); //To make sure value is YES. This is just for tesiting purpose.


    if(g_form.getValue('ad_domain') == 'YES'){



    if(g_form.getValue(user_confirm') == 'false' ){


    alert('Please be sure to check the box before submitting a ticket.');


    return false;


 


  }


  }


}



Please like or mark correct based on the impact of the response.


Gowrisankar Sat
Tera Guru

You can restrict the form submission, through onSubmit Client Scripts/ Business Rules.



onSubmit client scripts:



  1. function onSubmit() {      
  2.   if(g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'YESb' && g_form.getValue('question_choice') == 'incorrect info' ) //assuming values are YES and YESb    
  3.   {      
  4.             if(g_form.getValue('user_confirm') == 'false' ){      
  5.                   var result = confirm('Are you sure you wish to submit?');//or whatever that checkbox is for  
  6.                   if (result) {  
  7.                             g_form.setValue('checkbox', true);  
  8.                   else  
  9.                           return false;   //Here return false will stop the submission of the form.
  10.             }      
  11.   }      
  12. }    


Business Rules:



  1. (function executeRule(current, previous /*null when async*/) {  
  2. ....    
  3.   if (<condition to prevent delete>) {  
  4.   gs.addErrorMessage(gs.getMessage("You cannot delete a task where users have logged time against the task."));  
  5.   current.setAbortAction(true);     //setAbortAction will prevent the data to be inserted/updated
  6.   }  
  7. })(current, previous);