• Thomas_Miller
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
In reference to my own roadblock, and this post:  https://developer.salesforce.com/forums/?id=906F000000099TBIAY

Unless I'm missing something, it seems as though it is not possible to utilize both a user response "confirm" call (JS) and a reRender attribute on a command button. Here is the page and controller to test what I am pointing out; perhaps I'm making an error or there is another way.

Page
<apex:page controller="JSForwardToActionCon">
    <apex:form >

    <script>
    
        var x;
    
        function AreYouSure() { 
            x = confirm("Are you sure?");
            console.log('x: ' + x);
            return x;
        }
    </script>


  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page: JSforwardToAction
  <!-- End Default Content REMOVE THIS -->
  
    <br/><br/>
    <apex:outputLabel id="label" value="{!TheString}" />
    <br/><br/>
    <apex:commandButton action="{!AssignTheString}" value="Test" onClick="return AreYouSure();" >
        </apex:commandButton>
    
    </apex:form>
</apex:page>
Controller
public class JSForwardToActionCon {

    public String TheString;
    public String getTheString() {
        if (TheString == null) {
            TheString = 'test';
        }
        return TheString;
    }
    
    public Boolean UserResponse {get; set;}
    public void AssignTheString() {
        system.debug('UserResponse: ' + UserResponse);
    
        if (TheString == 'Assigned')
            TheString = 'test';    
        else if (TheString == 'test')
            TheString = 'Assigned';
    }

}

Now, modify the page and add a reRender="label" attribute to the command button. The user response no longer applies to the action method call in the controller. I believe this is due to the translation that occurs when VF is translated to HTML/AJAX calls when the reRender is used (uses JS to do this) and is a platform issue. I can confirm this is happening by viewing the source of both versions and locating the syntax error that occurs in the command button's onClick attribute of the HTML.

My question is - is there another way to accomplish this same task, or is this something that needs to go in Ideas and be implemented/fixed?

 
In reference to my own roadblock, and this post:  https://developer.salesforce.com/forums/?id=906F000000099TBIAY

Unless I'm missing something, it seems as though it is not possible to utilize both a user response "confirm" call (JS) and a reRender attribute on a command button. Here is the page and controller to test what I am pointing out; perhaps I'm making an error or there is another way.

Page
<apex:page controller="JSForwardToActionCon">
    <apex:form >

    <script>
    
        var x;
    
        function AreYouSure() { 
            x = confirm("Are you sure?");
            console.log('x: ' + x);
            return x;
        }
    </script>


  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page: JSforwardToAction
  <!-- End Default Content REMOVE THIS -->
  
    <br/><br/>
    <apex:outputLabel id="label" value="{!TheString}" />
    <br/><br/>
    <apex:commandButton action="{!AssignTheString}" value="Test" onClick="return AreYouSure();" >
        </apex:commandButton>
    
    </apex:form>
</apex:page>
Controller
public class JSForwardToActionCon {

    public String TheString;
    public String getTheString() {
        if (TheString == null) {
            TheString = 'test';
        }
        return TheString;
    }
    
    public Boolean UserResponse {get; set;}
    public void AssignTheString() {
        system.debug('UserResponse: ' + UserResponse);
    
        if (TheString == 'Assigned')
            TheString = 'test';    
        else if (TheString == 'test')
            TheString = 'Assigned';
    }

}

Now, modify the page and add a reRender="label" attribute to the command button. The user response no longer applies to the action method call in the controller. I believe this is due to the translation that occurs when VF is translated to HTML/AJAX calls when the reRender is used (uses JS to do this) and is a platform issue. I can confirm this is happening by viewing the source of both versions and locating the syntax error that occurs in the command button's onClick attribute of the HTML.

My question is - is there another way to accomplish this same task, or is this something that needs to go in Ideas and be implemented/fixed?