Issue while using custom java script on async command button

Hi
We have a requirement to add java script validations on various check boxes provided on task view form.We are trying to achieve this by adding it on Click(Java script on click event handler) available on Client-Side Events tab of async command button but custom java script does not work.Can you provide us some samples or guidelines to understand whats the issue.

Hi
could you provide some more details about what is not working? Or about what you’re doing in your js and what you expect it to do?
When you say validation on check boxes, I suppose you only want to check if they are checked or not, right?

best regards,
Javier

Hi Javier
Thanks for your reply.Yes i want to ensure if mandatory checkboxes have been checked when submit button has been clicked .Apart from this there are a few text boxes also which are mandatory and i want to add a custom java script to the async command button so that validations are done when submit button is clicked by user.

Hi
you have different options…

  • + Use the “required” flag
    + Evaluate check boxes and input fields value in the action called by the Async Command
    + Evaluate those fields in the Client-Side events

Have a look into the samples[url]http://communities.softwareag.com/ecosystem/communities/public/Developer/webmethods/tutorials/CAF/CAFSamples_80_Doc/Webm_caf_samples_80_index.html[/url] and the documentation for the JavaScript API [url]http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite8_ga/My_webMethods_and_Task_Engine/8-0-SP1_CAF_JavaScript_Reference/index.html[/url]
A sample JS could be (for v8.0.x):

var myCheckbox = CAF.model('#{caf:cid('my-checkbox-id')}');
if (myCheckbox.getValue()) {
  alert("checkbox is checked");
}

best regards,
Javier

Hi Javier
Thanks for your response.It works fine for me after modifying it as per my needs .It prompts me with an alert to fill mandatory fields but issue is once i click on OK on validation alert on web page task gets submitted instead action should not be executed unless mandatory fields have been filled by user.
Script used is on client side events under click.

Regards
Anuj

well, then you could do the validation in the java action (in my opinion, the simplest and easiest to maintain solution).
In case you want to stay with the javascript, you could add an async hidden command to perform the server side action and raise it if all your javascript checks pass. That way you’ll have a button to get the click and evaluate your checkboxes and a second button to call the action if all is ok.

best regards,
Javier

if you want the onclick javascript code to stop the processing of the click, you can just use a return statement like this:

return false;

Hi Eric and Javier
Thanks for all your responses.Issue is resolved now.

Regards
Anuj