Skip to main content
added 336 characters in body
Source Link
user24634
user24634

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

Is there a way I can pass this return value up to the onClick attr?

Gist Edit

<apex:commandLink value="Save" onclick="return Validation();" action="{!saveSettings}"/>                        


function Validation() {              
  alert('returning false');   
  return false;                    
}


// Alert shows 'returning false', action still executes.

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

Is there a way I can pass this return value up to the onClick attr?

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

Is there a way I can pass this return value up to the onClick attr?

Gist Edit

<apex:commandLink value="Save" onclick="return Validation();" action="{!saveSettings}"/>                        


function Validation() {              
  alert('returning false');   
  return false;                    
}


// Alert shows 'returning false', action still executes.
added 71 characters in body
Source Link
user24634
user24634

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

Is there a way I can pass this return value up to the onClick attr?

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

Is there a way I can pass this return value up to the onClick attr?

Editing to make clearer
Source Link
user24634
user24634

Block an action from executing via Javascript Function

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I perform some validation by checking a global var. If this is true, I I would like to stop the action from executing, and if not, execute the action by returning false.

function Validation() {
 
    if (unsavedChanges == true) {
        return false;
    } else {
        return true;
    } 
}

I realise return false; will only stop the default browser actionThe above method does not work, is there a way I can block {!ActionMethod} from executing with an onClick event?

My only other optionbut if I can think of is to use an action function for the actionput return false directly in the conditional, but I'd like to avoid this as muchonClick attribute the behaviour works as possible.expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />

Block an action from executing via Javascript

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I perform some validation by checking a global var. If this is true, I would like to stop the action from executing, and if not, execute the action.

function Validation() {
 
    if (unsavedChanges == true) {
        return false;
    } else {
        return true;
    } 
}

I realise return false; will only stop the default browser action, is there a way I can block {!ActionMethod} from executing with an onClick event?

My only other option I can think of is to use an action function for the action in the conditional, but I'd like to avoid this as much as possible.

Block an action from executing via Javascript Function

I have the following commandLink

<apex:commandLink value="Save" onClick="Validation();" action="{!ActionMethod}" />

When it's clicked, I would like to stop the action from executing by returning false.

function Validation() {
        return false;
}

The above method does not work, but if I put return false directly in the onClick attribute the behaviour works as expected:

<apex:commandLink value="Save" onClick="return false;" action="{!ActionMethod}" />
Source Link
user24634
user24634
Loading