You need to sign in to do that
Don't have an account?
How to stop javascript by calling ActionFunction tag
Hi All,
I have three action methods in different controllers which inserts records in three different objects. I am invoking the action methods through JavaScript (using ActionFunction Tag). i have some Standard validation rules on the three objects. When i am invoking the first action method using JavaScript, If an exception comes (Validation Rules) the second action method should not invoke.
Since it is a JavaScript all the action methods are getting called one by one even though exception(Validation Rules) occurs in the first action methods and error messages on the visualforce screen are being displayed and getting vanished.
So please suggest how to stop the JavaScript function if an exception occurs in the controllers.
Thanks
Srikanth.K
If an error occurs in the actionFunction, have your controller set a boolean value. Then in your javascript, you can do something like this.
I do that and it dosn't stop it, in fact it always returns false.
I got this flag in the controller
public Boolean possible { get; set; }
And I change it by this actionfunction
<apex:actionFunction action="{!isPosibleNewEvent}" name="isPosibleNewEvent" rerender="isPossible">
<apex:param name="posibleStartTime" assignTo="{!posibleStartTime}" value="" />
<apex:param name="posibleEndTime" assignTo="{!posibleEndTime}" value="" />
</apex:actionFunction>
And i have this logic at the javascript
isPosibleNewEvent(st.getTime(),ed.getTime());
alert({!possible}) ;
if({!possible)
jQuery("#gmCalendarNewEvent").show();
And the alert always shows false, any idea? or other way to do this !? thanks
What your doing should work, I would need to see your apex code.
No problem. Well, my first general advise is to clean up the code. Typically, a good refractor of the code can fix hidden spots where the bug originally hid or make it so you can easily pin point where the bug is.
The pagereference shouldn't matter. If you return null it tells visualforce to stay on the page. However since you are using it in an actionfunction and not an actionlink or actionbutton, I would make it void.
Another thing to make sure is that your apex:params tags are setting properties and the function within apex is parameterless. I am assumming you are doing this but I made that mistake at one point.
Since you don't want to post the code, print out some values in the console. Print out the values of start and end time within the apex code, and any other usefull information. It may help you narrow down what it is actually doing.