6

Use case:

  1. Conditionally render the 'Submit for approval' button based on some criteria while ...
  2. Exploiting apex:detail relatedList="true" relatedListHover="true" inlineEdit="true" and
  3. Hiding the 'Submit for approval' button once inlineedit is activated and
  4. Showing the 'Submit for approval' button once inlineedit is canceled

apex:detail has lots of usefulness: you get relatedLists for free, you get the related List Hovers for free, you get page layout buttons for free, and you can get inlineedit for free on your page layout. Inlineedit also is smart to hide all your standard page layout buttons (e.g. Edit, Clone, Delete, Sharing..) when you activate inline edit by double clicking, showing Save and Cancel in their place. If you Cancel, the standard page layout buttons come back

If I do something like the following:

<apex:page standardController="Foo__c" >
<apex:form id="theForm">
    <apex:pageBlock >
        <apex:pageBlockButtons location="top">
            <apex:commandButton id="submitBtn"
                                value="Submit for Approval"     
                                action="{!URLFOR($Action.Foo__c.Submit,Id)}" 
                                rendered="{!someCtlrProperty'}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    <apex:detail relatedList="true" relatedListHover="true" inlineEdit="true" 
                 showChatter="false" subject="{!Foo__c.id}"/>
</apex:form>    
</apex:page>

Objectives 1 and 2 are met but not 3 and 4

Solutions tried:

  1. Add <apex:inlineEditSupport hideOnEdit="submitBtn" resetFunction="resetInlineEdit" event="ondblclick"/> as child to apex:form. This does nothing. Activating inlineEdit on any detail page field isn't captured by the form component; even though it surrounds the apex:detail component

Alternatives

I. I know I can abandon apex:detail and build out the page using individual VF commandButton, pageBlock with child apex:inlineEditSupport that does show and hide, outputField, followed by relatedList components but this seems harder than necessary, especially with dozens of fields and I lose the relatedList Hover feature unless I implement something like this: related Idea. I also have to build / borrow the field history related list component/controller from here.

II. I also know I could abandon objectives 3 and 4 and rely on the users averting their eyes at the Submit for the Approval button while they are inline editing.

1

If you are not against using some simple jQuery on your VF page, this works for me in my dev org:

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"/>

        <script>

            $vfjq = jQuery.noConflict();

            $vfjq(document).ready(function() {
                $vfjq('form').on('click', 'div', function(event) {
                    var i = setInterval(function() {
                        if ($vfjq("input[value='Cancel']").css('display').indexOf('none') !== -1) {
                            $vfjq("input[value='Submit for Approval']").show();
                        } else {
                            $vfjq("input[value='Submit for Approval']").hide();
                        }
                        clearInterval(i);
                    }, 200);
                });
            });

        </script>
  • I just thought of something. You can probably just do this: $vfjq(document).ready(function() { if ("{!someCtlrProperty}" === "false") { $vfjq("input[value=Submit for Approval]").remove(); } } – Daniel N Jul 3 '13 at 20:25
  • That way you don't need your custom button, just put the standard one on the page. – Daniel N Jul 3 '13 at 20:33
  • sorry it took me so long to get back to this. Your solution in the code block works with the proviso that the apex:detail component also needs rerender="theForm" in scenarios where the button visibility is determined by values within the SObject. Thanks so much and it was a good excuse for me to finally learn jQuery. – cropredy Jul 30 '13 at 22:01
1

I think the more optimized way is to use ids instead of button values. since there might be more than one button with the same value on a page, ids will help us to solve this:

Belwo is the code , that we are using for a contract VF View Page.

    <script>

        $vfjq = jQuery.noConflict();

        $vfjq(document).ready(function() {
            $vfjq('form').on('click', 'div', function(event) {
                var i = setInterval(function() {
                    if ($vfjq("input[value='Cancel']").css('display').indexOf('none') !== -1) {

                        $vfjq("input[id*='editContract']").show();
                         $vfjq("input[id*='RightsWizard']").show();
                          $vfjq("input[id*='deleteButton']").show();
                           $vfjq("input[id*='uploadPDF']").show();
                            $vfjq("input[id*='addProduct']").show();
                             $vfjq("input[id*='cloneButton']").show(); 



                    } else {

                       $vfjq("input[id*='editContract']").hide();
                         $vfjq("input[id*='RightsWizard']").hide();
                          $vfjq("input[id*='deleteButton']").hide();
                           $vfjq("input[id*='uploadPDF']").hide();
                            $vfjq("input[id*='addProduct']").hide();
                             $vfjq("input[id*='cloneButton']").hide(); 

                    }
                    clearInterval(i);
                }, 800);
            });
        });

    </script>
  • agreed. this is what I ended up doing – cropredy Aug 2 '13 at 0:50
0

I think instead of using a custom button just use a standard "Submit for approval" button (add to the the page layout). Then it will be hidden or shown automatically depending on the inlineEdit status:

enter image description here

  • Thanks but this does not address objective 1 – cropredy Jul 3 '13 at 16:42
0

mast0r has a good point about the standard field, but it doesn't make the button show up only for certain criteria.

However, if the criteria are to only show the button for certain profiles, like Sys Admin, then you can create a new page layout, with the Submit for Approval button, and assign it to the Sys Admin profile, and assign the other layout, without the button, the all the other profiles.

  • Yes, this is true but the criteria for visibility is more complex than just user profile (albeit I used that in my example above) and my real world problem has several buttons with conditional visibility requirements – cropredy Jul 3 '13 at 16:41
  • I corrected the problem statement to use a controller-driven visibility condition – cropredy Jul 3 '13 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.