1

I have a requirement. I have a popup which is coming after I click on a zip record link In that popup I have a territory field whose value I need to give. Then record should be created in a table with zip name and territory name.

How to do it.? Here is my code--

function submit_Request(par1) { if(par1!=''){ myAction(par1); } }

`

    <apex:outputPanel id="popup" >

     <apex:outputPanel styleClass="popupBackground" layout="block"  rendered="{!displayPopUp}"/>
        <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}">

            <body>
                <table width="100%" height="100%" >



                    <tr height="20px" valign="top">
                        <td colspan="2" width="100%">
                            <table width="100%">
                                <tr>
                                    <td>

                                        Zip Name--- <apex:outputtext value="{!name}"></apex:outputtext>-->
                                    </td>
                                    <td>
                                        <h3> <apex:outputLabel > Destination Territory</apex:outputLabel></h3> &nbsp;&nbsp;

                                    <apex:inputfield value="{!Zip__c.Territory__r.Name}" id="memNam">
                                            <c:autoComplete autocomplete_textbox="{!$Component.memNam}" objectname="Territory__c" />
                                    </apex:inputfield> 

                                    </td>

                                    <td>

                                    <apex:commandButton value="Confirm" action="{!saveme}" oncomplete="submit_Request(document.getelementbyid('memNam').value);" />

                                     </td>
                                    <td  width="25%">
                                        <apex:commandButton value="Close" action="{!closePopup}" rerender="popup" />

                                    </td>                                        
                                </tr>
                            </table>
                        </td>
                    </tr>                      
                </table>
            </body>             

        </apex:outputPanel>`
  • The question is not very clear. Can you re-phrase and explain what you want to do? – Gaurav Kheterpal Jan 7 '14 at 9:30
  • I rephrased the question – Arun SFDC Jan 7 '14 at 14:20
2

There are a number of minor issues with this code; it's hard to tell exactly which issue is causing your problem. Here's a few items:

submit_Request(document.getelementbyid('memNam').value);

This isn't right, because it's a Visualforce-managed field, so you probably meant:

submit_Request(document.getelementbyid('{!$Component.popup.panel1.panel2.memNam}').value);

Or some other derivative (you should name the output panels with a unique ID).

The next piece of code is this:

<apex:inputfield value="{!Zip__c.Territory__r.Name}" id="memNam">
                                            <c:autoComplete autocomplete_textbox="{!$Component.memNam}" objectname="Territory__c" />
                                    </apex:inputfield> 

Which should probably be:

<apex:inputfield value="{!Zip__c.Territory__c}" id="memNam">
                                            <c:autoComplete autocomplete_textbox="{!$Component.memNam}" objectname="Territory__c" />
                                    </apex:inputfield> 

Binding to the ID value instead of the name gives you the ability to use a lookup window, particularly important if there is any possibility that there might be a duplicate territory record (e.g. more than one territory by the same name).

The other issues are mostly cosmetic code changes. However, since this is just a code fragment, I can't say for certain if there are other issues outside the current code fragment.

The body tag should be omitted in this code, since you're not supposed to have a body within a body. You also have a duplicate rendered attribute (e.g. if the outer element is rendered, the inner element will also be rendered). This can cause an unnecessary performance penalty.

Here's the sum of the suggested code changes:

<apex:outputPanel id="popup" >
     <apex:outputPanel styleClass="popupBackground" layout="block"  rendered="{!displayPopUp}"/>
        <apex:outputPanel styleClass="customPopup" layout="block">
            <body>
                <table width="100%" height="100%" >
                    <tr height="20px" valign="top">
                        <td colspan="2" width="100%">
                            <table width="100%">
                                <tr>
                                    <td>
                                        Zip Name--- <apex:outputtext value="{!name}"></apex:outputtext>-->
                                    </td>
                                    <td>
                                        <h3> <apex:outputLabel > Destination Territory</apex:outputLabel></h3> &nbsp;&nbsp;
                                    <apex:inputfield value="{!Zip__c.Territory__c}" id="memNam">
                                            <c:autoComplete autocomplete_textbox="{!$Component.memNam}" objectname="Territory__c" />
                                    </apex:inputfield> 
                                    </td>
                                    <td>
                                    <apex:commandButton value="Confirm" action="{!saveme}" rerender="popup" oncomplete="submit_Request(document.getelementbyid('{!$Component.memNam}').value);" />
                                     </td>
                                    <td  width="25%">
                                        <apex:commandButton value="Close" action="{!closePopup}" rerender="popup" />
                                    </td>                                        
                                </tr>
                            </table>
                        </td>
                    </tr>                      
                </table>
            </body>             
        </apex:outputPanel>

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.