I'm working on a custom visual force contact search page.
Here's what I'm trying to achieve:
A user would input either a Name, Phone Number or Email Address into the corresponding fields on the page. After that, they would either click the "Search Contacts" or "Clear Fields" Button.
If "Search Contacts" is clicked, a table below would be populated with all contacts with fields matching the previous input.
If "Clear Fields" is clicked, all the input fields on the page will be cleared.
Currently I don't have any errors but neither button seems to work. Could anyone tell me where I went wrong and how to fix it?
My Page
<apex:page id="ContactPage" controller="Ctrl_ContactSearch">
<apex:tabPanel id="ContactPanel">
<apex:tab id="ContactTab" label="Contact Search">
<apex:form id="ContactForm">
<apex:pageBlock title="Contact Search Page" id="ContactBlock">
<!-- Buttons -->
<apex:pageBlockButtons location="top">
<apex:commandButton value="Search Contacts" action="{!searchContacts}" reRender="contact-table" />
<input type = "button" value="Clear Fields" onclick="(ClearFields)" />
</apex:pageBlockButtons>
<!-- Input Fields -->
<apex:pageBlockSection id="contact-table" columns="3">
<apex:pageBlockSectionItem id = "NameInputBlock">
<apex:outputLabel value="Name" />
<apex:inputText id = "NameInputField" value="{!name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id = "PhoneInputBlock">
<apex:outputLabel value="Phone" />
<apex:inputText id = "PhoneInputField" value="{!Phone}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id = "EmailInputBlock">
<apex:outputLabel value="Email" />
<apex:inputText id = "EmailInputField" value="{!Email}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<!-- Results Display -->
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column>
<apex:facet name="header">Name</apex:facet>
{!c.Name}
</apex:column>
<apex:column>
<apex:facet name="header">Phone Number</apex:facet>
{!c.Phone}
</apex:column>
<apex:column>
<apex:facet name="header">Email</apex:facet>
{!c.Email}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:tab>
</apex:tabPanel>
<script>
public string ClearFields()
{
document.getElementById('{$Component.ContactPage:ContactPanel:ContactTab:ContactForm:ContactBlock:contact-table:NameInputBlock:NameInputField}').value = '';
document.getElementById('{$Component.ContactPage:ContactPanel:ContactTab:ContactForm:ContactBlock:contact-table:PhoneInputBlock:PhoneInputField}').value = '';
document.getElementById('{$Component.ContactPage:ContactPanel:ContactTab:ContactForm:ContactBlock:contact-table:EmailInputBlock:EmailInputField}').value = '';
}
</script>
</apex:page>
My Controller
public with sharing class Ctrl_ContactSearch
{
public List<Contact> contacts { get; set; }
public String name { get; set; }
public String phone { get; set; }
public String email { get; set; }
public PageReference searchContacts()
{
contacts = [select Name, Phone, Email from Contact where Name = :name or Phone = :phone or email = :email];
return null;
}
}