My visualforce page contains a modal with a new contact form. When saved, the new record is correctly added to the contact list on the page. However, if you reopen the modal, the input fields still contain the values from the recently-saved record. How can I reset the form after each save to allow multiple uses?
I tried rerendering the form, but then realized this doesn't affect the controller. I know this can be achieved through a page refresh (via redirect), but am hoping there might be a better solution. Any ideas?
Markup:
<apex:form>
<apex:inputField id="newContactName" value="{!newContact.Name}"/>
<apex:inputField id="newContactAddress" value="{!newContact.Address}"/>
<button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<apex:commandButton value="Save" action="{!saveContact}"/>
</apex:form>
Apex:
public class custom_extension {
public Customer__c customer;
public Contact__c newContact {get; set;}
public custom_extension(ApexPages.StandardController controller) {
this.customer = (Customer__c)controller.getRecord();
newContact = new Contact__c();
}
public PageReference saveContact() {
newContact.Customer_Vendor__c = ApexPages.currentPage().getParameters().get('id');
insert newContact;
return null;
}
}