function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BDArnzBDArnz 

Insert record with in-line edit?

I have a VF page showing multiple custom objects with related lists.  (Lists within lists actually).  I have enabled inline edit for all of the fields and it works great.  Double click the field, edit, click save.  Save, cancel and new buttons all show and hide as expected.

 

My challenge is when inserting new records.  I do NOT want to go the standard object detail screen to enter the information into the fields.  (multiple linked and nested objects/lists means a lot of 'bouncing' back and forth that I want to avoid the user getting lost in.  I would like for them to stay on the same page essentially inserting the record directly into the list).

 

My 'New' button adds a record to the list which adds and displays the new record properly.  It has default text instructing the user to double click to edit.  I would rather have the newly created record show up already 'in' inline edit mode.

 

Does anyone know of a way to initiate in-line edit mode without requiring the user to click or double click somewhere?  I'm open to solutions either from the VF page doing it or the controller...

 

Thanks for listening (or reading...)

Saurabh DhobleSaurabh Dhoble

Can you please post your code, especially the part where you add a new record when the New button is clicked.

 

You might be able to somehow call the "dblClick" javascript event as soon as the new row is created- that way it will be editable to the user.

BDArnzBDArnz

I'd be happy to.  I'll post the less complicated one.  This page only has a single level list and table:

 

Here's the Page:

 

<apex:page standardController="RMA__c" extensions="RMA_Ext">
	<apex:form >
		<apex:outputText value="{!Message}" rendered = "{!LEN(Message)}>0"/>
		<apex:detail subject="{!RMA__c.Id}" relatedList="false" title="true" inlineEdit="true"  />
		<apex:pageBlock title="RMA Line Items" >
			<apex:pageBlockButtons >
				<apex:commandButton action="{!Save}" id="saveButton" value="Save"  style="display: none;" />
				<apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"  style="display: none;" />
				<apex:commandButton action="{!newItem}" id="newItemButton" value="New Part" />
			</apex:pageBlockButtons>
			<apex:pageMessages />
			<apex:pageBlockSection >
        		<apex:pageBlockTable value="{!LineItems}" var="LI" id="itemstable">
					<apex:column headerValue="Del">
						<apex:commandLink value="Del" 
							title="Delete this Line Item"
							action="{!delItem}" 
							rerender="itemstable">
	   						<apex:param name="DoomedItemID" value="{!LI.id}" assignTo="{!DoomedItem}"/>
						</apex:commandLink>
					</apex:column>
					<apex:column headerValue="Ship">
						<apex:outputField value="{!LI.Ship__c}">
								<apex:inlineEditSupport event="ondblClick" 
									showonEdit="saveButton,cancelButton" 
									hideonEdit="newItemButton"/>
						</apex:outputField>
					</apex:column>
					<apex:column headerValue="Scrap">
						<apex:outputField value="{!LI.Scrap__c}">
								<apex:inlineEditSupport event="ondblClick" 
									showonEdit="saveButton,cancelButton" 
									hideonEdit="newItemButton"/>
						</apex:outputField>
					</apex:column>
					<apex:column headerValue="Return">
						<apex:outputField value="{!LI.Return__c}">
								<apex:inlineEditSupport event="ondblClick" 
									showonEdit="saveButton,cancelButton" 
									hideonEdit="newItemButton"/>
						</apex:outputField>
					</apex:column>
					<apex:column headerValue="Qty">
						<!-- <apex:actionRegion >  -->
							<apex:outputField value="{!LI.Quantity__c}">
								<apex:inlineEditSupport event="ondblClick" 
									showonEdit="saveButton,cancelButton" 
									hideonEdit="newItemButton"/>
							</apex:outputField>
						<!--  </apex:actionRegion>  -->
					</apex:column>
					<apex:column headerValue="Part Number">
						<apex:outputField value="{!LI.Part_Number__c}">
							<apex:inlineEditSupport event="ondblClick" 
								showonEdit="saveButton,cancelButton" 
								hideonEdit="newItemButton"/>
						</apex:outputField>
					</apex:column>
					
					<apex:column headerValue="Description">
							<apex:outputField value="{!LI.Description__c}"/>
					</apex:column>
        		</apex:pageBlockTable> 
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

And the controller:

 

public with sharing class RMA_Ext {

	Private ApexPages.StandardController std;
	Public String message{get;set;}
	Public Boolean editLI{get;set;}
	Public RMA__c thisRMA {get;set;}  
	public String DoomedItem {get; set;}
	
	//List of RMA Items
	Public List<RMA_Item__c> LineItems {get;set;}
	
	Public RMA_Ext(ApexPages.StandardController stdCtrl){
		std = stdCtrl;
        thisRMA = (RMA__c)stdCtrl.getRecord();  //get this RMA



		editLI = false;
		LineItems = [
			select Id,
			Ship__c,
			Serial_Number__c,
			Scrap__c,
			Return__c,
			Quantity__c,
			Part_Number__c,
			Name,
			Description__c
			From RMA_Item__c
		];	
	}
	
	Public PageReference save(){
        String EndPoint, RequestBody, test, bodyval;
        Http http = new Http();
        HttpRequest req = new HttpRequest();

		
		for (RMA_Item__c li:LineItems){
			
        //setup the HTTP callout
		
			li.Description__c = getDFDescription(li.Part_Number__c);
			
		}
		//save the RMA
		std.Save();
		//Save line items
		update LineItems;
		PageReference result = ApexPages.currentPage();
		result.setRedirect(true);
		return result;
	}
	
	
	
	
 	Public PageReference delItem(){
 		RMA_Item__c DItem = new RMA_Item__c(id=DoomedItem);
 		Delete DItem;
        PageReference delItem = new PageReference('/' + thisRMA.Id);
		delItem.setRedirect(true);
		return delItem;
 	}
	
	
    Public PageReference newItem(){
    	RMA_Item__c item = new RMA_Item__c();
    	item.Part_Number__c = 'New';
    	item.Quantity__c = 0;
    	item.RMA__c = thisRMA.Id;
    	insert item;

        PageReference newItem = new PageReference('/' + thisRMA.Id);
		newItem.setRedirect(true);
		return newItem;
    }

 

 

I haven't worked with the javascript much so if you know how to work that it might be a good option...

 

Thanks!