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
SayasoniSayasoni 

Help with inputText Value

I have a visualforce page that searches for contacts based on FirstName & LastName.The firstname & lastname fields are autopopulated using the email address value from another custom object.

However, i would also like the user to have the ability to edit the auto-populated firstname & lastname values with their on input before the search. The problem is the page only seems to perform the search using only the original auto-populated values & will not accept newly user input values,since everytime the user input values & clicks the search button,the PageBlockSection refreshes and fill the fields with the original auto-populated values.

Kindly advice on how to make the input text field accept both autopopulated values as well as user input values.

Below is some part of my wrapper class & visualforce page.

public String  firstName;
public String  lastName;
public String userinput;
public String userinp;
public List<cContact> contactList {get; set;}  

Public List<Contact> results = new List<Contact>();
 
/* Getter and setter methods for getting the user input ie. Contact name from the UI */ public String getUserinput(){return userinput;} public void setUserinput(String userinp){this.userinput=userinp;} public String getUserinp(){return userinp;} public void setUserinp(String userinp){this.userinp=userinp;}
//Getter and setters for firstname and lastname
/* Method to Search the contact database to fetch the query results */ public List<Contact> contactsearch() { contactList = new List<cContact>(); for(Contact c : [select Account.Name,Name,Alternative_Email_Address1__c,Alternative_Email_Address2__c,Assistant_s_Email2__c,FirstName,LastName,Email,title,Id from Contact where Email like :userinput+'%' and (FirstName = :firstName or FirstName like :userinp+'%' )and (LastName = :lastName or LastName like :userin+'%') ]) { contactList.add(new cContact(c)); } return null; }
/* Method for returning the contact search results to the UI */
public List<cContact> getResults()
{  
  return contactList;
}

 

<apex:form >
<apex:sectionHeader title="Step 1" subtitle="Select Client(s) to Add to:"/>
<apex:pageblock id="theBlock">
<apex:pageMessages /> <!-- this is where the error messages will appear -->
<apex:pageBlockSection title="Search Contacts" columns="1" ></apex:pageBlockSection>
<!-- Div to give a colored box effect -->
<div style="border-width:2px;border-style:solid;border-color:orange;">
    <!-- Panel grid to display boxes for accepting user input values -->
    <apex:panelGrid columns="2" >
        <apex:outputLabel style="font-weight:bold;" value="Client First Name" ></apex:outputLabel>
        <apex:inputText value="{!firstName}" id="firstName" disabled="false" />
        <apex:outputLabel style="font-weight:bold;"  value="Client Last Name" ></apex:outputLabel>
        <apex:inputText value="{!lastName}" id="lastName" disabled="false"  />
     </apex:panelGrid>
    <!-- End of panelgrid -->
    <!-- Div to position the commandbutton appropriately -->
        <div style="position:relative;left:75px;">
             <apex:commandButton value="Search" action="{!contactsearch}" reRender="theBlock"/>
        </div>
    <!-- End of div -->

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SayasoniSayasoni

I finally got it everything to work fine.All i needed was to check for null in the firstname and lastname getter methods and rerender the search button on the visualforce page.

All Answers

SayasoniSayasoni

Anyone with a clue.Am really stuck.

SayasoniSayasoni

I finally managed to make it accept user input & make it search on both the original auto-populated value as well as newly entered user input values.It was all in the SOQL query inside the contactsearch() method.

 

Now the only problem remaining is having the firstname & lastname fields maintain the newly user input search values rather than refreshing the values to their original auto-filled once you click on the search button.

 

Screenshot 1 is the first search with the original auto-filled values:

https://c.na7.content.force.com/servlet/servlet.ImageServer?id=015A00000022YQ7&oid=00DA0000000AZxT&lastMod=1336564292000

 

Screenshot2 how i would like it to be when i replace the autofilled value with my own user input(firstName: meg):

https://c.na7.content.force.com/servlet/servlet.ImageServer?id=015A00000022YQC&oid=00DA0000000AZxT&lastMod=1336564339000

 

Screen3 how it works now replacing the original user input value with the original auto-filled values:

https://c.na7.content.force.com/servlet/servlet.ImageServer?id=015A00000022YLv&oid=00DA0000000AZxT&lastMod=1336564375000

 

 

SayasoniSayasoni

I finally got it everything to work fine.All i needed was to check for null in the firstname and lastname getter methods and rerender the search button on the visualforce page.

This was selected as the best answer
Amit_Amit_
Hi Sayasoni ,
I am having the same requiremnt can you just tell me how you have achived this requirement. right now I am just writing an SOQL over the search Field, how will I make it search over InputText and Picklist value.