Search Here

apex: inputText Component in Visualforce Page

 The <apex: inputText> is another important component used for creating an HTML input element of type text. The <apex: inputText> is used for getting the input from the user for the controller method that doesn't correspond to a field on a Salesforce object.


The HTML pass-through attributes are supported by this component using the "html-" prefix, which will be attached to the generated <input> tag.


The <apex: inputText> component has the following attributes:


1. accesskey

The acesskey is a string type attribute that defines the keyboard access key that puts the field in focus.


Syntax


<apex:inputText accesskey="f"></apex:inputText>  

2. alt

The alt is a string-type attribute used to define the field's alternative text description.


Syntax


<apex:inputText alt="Alternative Text Here"></apex:inputText>  

3. dir

The dir is a string-type attribute used to specify the direction in which the generated HTML component should be used. RTL and LTR are the two possible values for the dir attribute.


Syntax


<apex:inputText dir="RTL"></apex:inputText>  

4. disabled

The disabled is a Boolean type attribute that specifies whether this text box should be displayed in the disabled state or not. By default, its value is set to false.


Syntax


<apex:inputText disabled="true"></apex:inputText>  

5. id

The id is a string type attribute, i.e., a unique identifier that allows this component to be referenced by other components in the page.


Syntax


<apex:inputText id="inputId"></apex:inputText>  

6. label

The label is a string-type attribute used to display text next to the control and reference the control in the error message.


Syntax


<apex:inputText label="Label Text"></apex:inputText>  

7. lang

The lang is a string-type attribute used for specifying the base language used for the generated HTML output. The possible values of this attribute are en and en-US.


Syntax

AD


<apex:inputText lang="en"></apex:inputText>  

8. list

The list is an Object type attribute, i.e., a list of auto-complete values to be added to an HTML <datalist> block associated with the input field. This attribute is either a comma-delimited static string or a VF expression.


Syntax


<apex:inputText list="listName"></apex:inputText>  

9. onblur

The onblur is a string-type attribute used to invoke the JavaScript method when the onblur event occurs or simply when the focus moves off the field.


Syntax:


<apex:inputText onblur="saveRecords();"></apex:inputText>  

10. maxlength

The maxlengh is an Integer type attribute that specifies the maximum number of characters that the user for this field can enter.

AD


Syntax:


<apex:inputText maxlength="1024"></apex:inputText>  

11. onchange

The onchange is a string-type attribute used to invoke the JavaScript method when the onchange event occurs or when the user changes the field's content.


Syntax:


<apex:inputText onchange="saveRecords();"></apex:inputText>  

12. onclick

The onclick is a string-type attribute used to invoke the JavaScript method when the onclick event occurs or when the user clicks the field.


Syntax:


<apex:inputText onclick="saveRecords();"></apex:inputText>  

13. ondblclick

The ondblclick is a string type attribute used to invoke the JavaScript method when the ondblclick event occurs or simply when the user clicks the field twice.


Syntax:


<apex:inputText ondblclick="saveRecords();"></apex:inputText>  

14. onfocus

The onfocus is a string-type attribute used to invoke the JavaScript method when the input event occurs or the focus is on the field.


Syntax:


<apex:inputText onfocus="saveRecords();"></apex:inputText>  

15. onkeydown

The onkeydown is a string-type attribute used to invoke the JavaScript method when the onkeydown event occurs or simply when the user presses a keyboard key.


Syntax:


<apex:inputText onkeydown="saveRecords();"></apex:inputText>  

16. onkeypress

The onkeypress is a string-type attribute used to invoke the JavaScript method when the onkeypress event occurs or simply when the user holds down or presses a keyboard key.


Syntax:


<apex:inputText onkeypress="saveRecords();"></apex:inputText>  

17. onkeyup

The onkeyup is a string-type attribute used to invoke the JavaScript method when the onkeyup event occurs or when the user releases a keyboard key.


Syntax:


<apex:inputText onkeyup="saveRecords();"></apex:inputText>  

18. onmousedown

The onmousedown is a string-type attribute used to invoke the JavaScript method when the onmousedown event occurs or simply when the user presses the mouse button.


Syntax:


<apex:inputText onmousedown="countKeys();"></apex:inputText>  

19. onmousemove

The onmousemove is a string-type attribute used to invoke the JavaScript method when the onmousemove event occurs or simply when the user moves the mouse pointer.


Syntax:


<apex:inputText onmousemove="countKeys();"></apex:inputText>  

20. onmouseout

The onmouseout is a string-type attribute used to invoke the JavaScript method when the onmouseout event occurs or simply when the user moves the mouse pointer away from the field.


Syntax:


<apex:inputText onmouseout="countKeys();"></apex:inputText>  

21. onmouseover

The onmouseover is a string-type attribute used to invoke the JavaScript method when the onmouseover event occurs or simply when the user moves the pointer over the input.


Syntax:


<apex:inputText onmouseover="countKeys();"></apex:inputText>  

22. onmouseup

The onmouseup is a string-type attribute used to invoke the JavaScript method when the onmouseup event occurs or when the user releases the mouse button.


Syntax:


<apex:inputText onmouseup="countKeys();"></apex:inputText>  

23. rendered

The rendered is a Boolean type attribute that specifies whether this component needs to be rendered on the page or not. By default, its value is set to true.


Syntax:


<apex:inputText rendered="countKeys();"></apex:inputText>  

24. required

The required is a Boolean type attribute that specifies whether this field is a required field or not. By default, its value is set to false.


Syntax:


<apex:inputText required="true"></apex:inputText>  

25. size

The size is an Integer type attribute used to specify the width of the input field. Width is expressed by the number of characters displayed at a time.


Syntax:


<apex:inputText size="50"></apex:inputText>  

26. style

The style is a string type attribute used to specify the inline CSS style that will be applied for displaying the input component.


Syntax:


<apex:inputText style="display:none;"></apex:inputText>  

27. styleClass

The styleClass is a string type attribute used to specify the style class that will be applied for displaying the input component.


Syntax:


<apex:inputText styleClass="inputClass"></apex:inputText>  

28. tabindex

The tabindex is a string type attribute used to specify the order in which this field is selected compared to other page components when a user presses the Tab key repeatedly. The value of this attribute should be between 0 to 32767.


Syntax:


<apex:inputText tabindex="1024"></apex:inputText>  

29. title

The title is a string-type attribute that specifies the text to display as a tooltip when the user's mouse pointer hovers over this component.


Syntax:


<apex:inputText title="Image Title"></apex:inputText>  

30. value

The value is an Object type attribute, i.e., an expression that references the controller class variable associated with this field.


Syntax:


<apex:inputText value="{!variableName}"></apex:inputText>  

Let's take an example to understand how we can use the <apex: inputText> component on the Visualforce page.


ApexInputTextExample.vfp


<!-- create apex page with custom controller-->  

<apex:page standardController="Contact" extensions="ApexInputController" docType="html-5.0">  

    <!-- use apex form to show the accounts and contacts table-->  

    <apex:form id="changeStatusForm">  

        <apex:pageBlock title="Account/Contact Information">  

            <!-- command buttons are responsible for showing accounts in the table-->  

            <apex:pageMessages />  

            <apex:pageBlockSection title="Account Information">  

                <apex:inputText  value="{!accName}" label="Account Name"/>  

                <apex:inputText  value="{!accAccountNumber}" label="Account Number"/>  

                <apex:inputText  value="{!accPhone}" label="Phone"/>  

                <apex:inputText  value="{!accRating}" label="Rating"/>  

                <apex:inputText  value="{!accWebsite}" label="Website"/>  

            </apex:pageBlockSection>  

              

            <apex:pageBlockSection title="Contact Information">  

                <apex:inputText  value="{!conFirstName}" label="First Name"/>  

                <apex:inputText  value="{!conLastName}" label="Last Name"/>  

                <apex:inputText  value="{!conAccountId}" label="Account Id"/>  

                <apex:inputText  value="{!conEmail}" label="Email"/>  

                <apex:inputText  value="{!conPhone}" label="Phone"/>  

            </apex:pageBlockSection>  

        </apex:pageBlock>  

    </apex:form>  

</apex:page>   

ApexInputTextController.apxc


// create ApexInputTextController class to get list of Accounts and Contacts  

public class ApexInputTextController {  

    public string accName{get;set;}  

    public string accAccountNumber{get;set;}  

    public string accPhone{get;set;}  

    public string accRating{get;set;}  

    public string accWebsite{get;set;}  

    public string conFirstName{get;set;}  

    public string conLastName{get;set;}  

    public string conAccountId{get;set;}  

    public string conEmail{get;set;}  

    public string conPhone{get;set;}  

      

    public String conId {get;set;}  

      

    //default constructor to get record Id from the page  

    public ApexInputTextController(ApexPages.StandardController controller){  

        conId = controller.getRecord().Id; //'001x00000035SxX' ;  

        Contact con = [Select Id, FirstName, LastName, AccountId, Email, Phone From Contact Where Id =:conId];  

        Account acc = [Select Id, Name, AccountNumber, Phone, Rating, Website From Account where Id =:con.AccountId ];  

          

        accName = acc.Name;  

        accAccountNumber = acc.AccountNumber;  

        accPhone = acc.Phone;  

        accRating = acc.Rating;  

        accWebsite = acc.Website;  

        conFirstName = con.FirstName;  

        conLastName = con.LastName;  

        conAccountId = con.AccountId;  

        conEmail = con.Email;  

        conPhone = con.Phone;  

    }  

}  


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.