You need to sign in to do that
Don't have an account?
rahma bhb
callback only called when developer tools/ Lightning components
Hi,
I am calling a method saveData from my js controller when all the fields of my form are filled :
The callback of this method is never called - and when I open the developer tools , the callback function is called and working fine
does any one has an explanation of why the code is only working when open the developer tools in the browser please?
I am calling a method saveData from my js controller when all the fields of my form are filled :
$("#myForm").validate({ rules: { title: {required: true}, firstname: {required: true}, lastname: {required: true}, }, messages: { title: "Please type and select a title", firstname: "Please enter the client first name", lastname: "Please enter the clients last name", }, tooltip_options:{ '_all_': {placement: 'top'}, }, focusInvalid: false, submitHandler: function() { if($('#confirmation').prop("checked") == false ){ helper.showErrorMessage(); }else { helper.saveData(component); } } }); },
The callback of this method is never called - and when I open the developer tools , the callback function is called and working fine
saveData: function(component){ var action = component.get("c.saveClient"); actionJInsured.setParams({ "firstname": firstname, "lastname": lastname, "title": "title" }); action .setCallback(this, function(response){ var state = response.getState(); if (component.isValid() && state === "SUCCESS") { alert('inside the callback'); } }); $A.enqueueAction(action); }
does any one has an explanation of why the code is only working when open the developer tools in the browser please?
you have named your variable as "action" in this line:
var action = component.get("c.saveClient");
In the next line you are referring it by the name "actionJInsured" instead of action.
actionJInsured.setParams
Thank you for your reply
This did not solve the issue sadly, the callback function does not seem to be entered at all
Not sure if this is a bug in Salesforce Lightning as when I open the developer tool all the code inside the callback
is executed and works fine.
I just noticed a space between action and .setCallback. I think that is the problem. it needs to be
action.setCallback....
Thank you for getting back to me
Not solving the issue either,
When I call this method when I click the button it works fine (without opening the developer tool)
and when I call the same method from the submit handler (form validation), then it does not work (and works when I
open the developer tool) - have you had any similar issue before ?
besides, it enters the saveClient method and does not enter the callback - and again if inspect the code and open the
developer tool the code continue to execute - it seems like it is blocked at this stage for some reason
did you get any solution for above issue?