How to use the lightning-formatted-email, lightning-formatted-number, lightning-formatted-phone, lightning-formatted-date-time, lightning-formatted-text, lightning-formatted-address, lightning-formatted-url in Salesforce lightning web component (LWC) | how to display of lightning-formatted input fields and there values in Salesforce LWC (Lightning Web Component)

7,669 views

Hey guys, today in this post we are going to learn about How to use the lightning-formatted-email, lightning-formatted-number, lightning-formatted-phone, lightning-formatted-date-time, lightning-formatted-text, lightning-formatted-address, lightning-formatted-url in Salesforce lightning web component (LWC).

A lightning-formatted-text component displays a read-only representation of text, and can convert URLs and email addresses to links, or “linkify” them. Click more about lightning-formatted-text.

A lightning-formatted-time component displays a read-only representation of time in the user’s locale format. A valid ISO8601 formatted time string must be used. To know more about lightning-formatted-time, Click Here.

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!

 

A lightning-formatted-number component displays formatted numbers for decimals, currency, and percentages. Use format-style to specify the number style. This component uses the Intl.NumberFormat JavaScript object to format numerical values. Click here to know more about lightning-formatted-number.

A lightning-formatted-phone component displays a read-only representation of a phone number as a hyperlink using the tel: URL scheme. Clicking the phone number opens the default VOIP call application on a desktop. On mobile devices, clicking the phone number calls the number. To know more about lightning-formatted-phone, Click Here.

 

 

Files we used to create lightning-formatted in Salesforce LWC →

lwcFormattedInput.html LWc HTML File Template HTML file to display lightning formatted field’s value in Salesforce Lightning Web Component (LWC)
lwcFormattedInput.js LWC JavaScript File It’s hold import & export method in Salesforce LWC.
lwcFormattedInput.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as lightning__AppPage, lightning__RecordPage, lightning__HomePage.

 

Final Output →

use the lightning formatted fields in lwc -- w3web.net
 

 

You can download file directly from github by Click Here.

 
 

Other related post that would you like to learn in Salesforce

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  • Find the below steps ▾

 

Create Lightning Web Component HTML →

Step 1:- Create Lightning Web Component HTML ➡ lwcFormattedInput.html

SFDX:Lightning Web Component ➡ New ➡ lwcFormattedInput.html

lwcFormattedInput.html [Lightning Web Component HTML]

  1.    <template>
  2. <lightning-card>
  3.     <div class="slds-p-around_medium">
  4.         <h3 class="slds-text-heading_small"><lightning-icon icon-name="custom:custom94" size="small"></lightning-icon> <strong style="color:#270086; font-size:13px; margin-right:5px;"> Create Formatted Email, Formatted Number, Formatted Phone, Formatted date-time, Formatted Time, Formatted Text, Formatted Address and Formatted Url in Lightning Web Component (LWC) </strong></h3>
  5.         <br/><br/>
  6.         <table class="slds-table slds-table_cell-buffer slds-table_col-bordered slds-table_bordered" style="border:1px #ddd solid;">
  7.         <tbody>
  8.             <tr>
  9.                 <td style="vertical-align: top;">                   
  10.                         <h2 class="header" style="color: #ff8000;"><strong>Formatted Email</strong> </h2>
  11.                         <p><lightning-formatted-email value="email@example.com" ></lightning-formatted-email></p>   
  12.                         <p><lightning-formatted-email value="email@example.com" hide-icon></lightning-formatted-email></p>
  13.                         <p><lightning-formatted-email value="email@example.com" label="Email Us!" ></lightning-formatted-email></p>
  14.                 </td>
  15.                 <td style="vertical-align: top;">                    
  16.                         <h2 class="header" style="color: #ff8000;"><strong>Formatted Number</strong> </h2>
  17.                         <p><lightning-formatted-number value="1234.5678"></lightning-formatted-number></p>
  18.                         <p><lightning-formatted-number value="1234.5678" maximum-fraction-digits="2"></lightning-formatted-number></p>
  19.                         <p><lightning-formatted-number value="12.34" format-style="decimal" minimum-integer-digits="5"></lightning-formatted-number></p>
  20.                         <p><lightning-formatted-number value="12.34" format-style="decimal" minimum-fraction-digits="5"></lightning-formatted-number></p>
  21.                         <p><lightning-formatted-number value="12.34" format-style="decimal" minimum-significant-digits="5"></lightning-formatted-number></p>
  22.                         <p><lightning-formatted-number value="123456789.123456789" minimum-fraction-digits="9"></lightning-formatted-number></p>
  23.                 </td>
  24.             </tr>
  25.             <tr>
  26.                 <td style="vertical-align: top;">                
  27.                     <h2 class="header" style="color: #ff8000;"><strong>Formatted Phone</strong> </h2>
  28.                     <p><lightning-formatted-phone value="+18005551212" ></lightning-formatted-phone></p>
  29.                     <p><lightning-formatted-phone value="8005551212"></lightning-formatted-phone></p>
  30.                     <p><lightning-formatted-phone value="18005551212"></lightning-formatted-phone></p>
  31.                     <p><lightning-formatted-phone value="1333333334" ></lightning-formatted-phone></p>
  32.                     <p><lightning-formatted-phone value="18005551212" disabled></lightning-formatted-phone></p>                
  33.                 </td>
  34.                 <td style="vertical-align: top;">                
  35.                     <h2 class="header" style="color: #ff8000;"><strong>Formatted date-time</strong></h2>
  36.                     <p><lightning-formatted-date-time value="1547250828000"></lightning-formatted-date-time></p>
  37.                     <p><lightning-formatted-date-time value="1547250828000" year="2-digit" month="short" day="2-digit" weekday="narrow"></lightning-formatted-date-time></p>
  38.                     <p><lightning-formatted-date-time value="1547250828000" year="2-digit" month="short" day="2-digit" weekday="long"></lightning-formatted-date-time></p>                
  39.                 </td>
  40.             </tr>
  41.             <tr>
  42.                 <td style="vertical-align: top;">                    
  43.                         <h2 class="header" style="color: #ff8000;"><strong>Formatted Time</strong></h2>
  44.                         <p>Simple Time value: <lightning-formatted-time value="22:12:30.999"></lightning-formatted-time></p>
  45.                         <p>Time value with Z suffix: <lightning-formatted-time value="22:12:30.999Z"></lightning-formatted-time></p>                    
  46.                 </td>
  47.                 <td style="vertical-align: top;">                    
  48.                         <h2 class="header" style="color: #ff8000;"><strong>Formatted Text</strong></h2>
  49.                         <p><lightning-formatted-text value="Email salesforce.com and info.salesforce.com" ></lightning-formatted-text></p>
  50.                         <p><lightning-formatted-text value="Email info@salesforce.com" ></lightning-formatted-text></p>
  51.                         <p><lightning-formatted-text value="Email salesforce.com and info.salesforce.com" linkify></lightning-formatted-text></p>
  52.                         <p><lightning-formatted-text value="Email info@salesforce.com" linkify></lightning-formatted-text></p>                    
  53.                 </td>
  54.  
  55.             </tr>
  56.  
  57.             <tr>
  58.                 <td style="vertical-align: top;">
  59.                     <h2 class="header" style="color: #ff8000;"><strong>Formatted Address</strong></h2>
  60.                     <lightning-formatted-address
  61.                     street="121 Spear St."
  62.                     city="San Francisco"
  63.                     country="US"
  64.                     province="CA"
  65.                     postal-code="94105"
  66.                 ></lightning-formatted-address>
  67.                 <h2 class="header" style="color: #ff8000;"><strong>Formatted Address in Plain Text</strong></h2>
  68.                 <lightning-formatted-address
  69.                 street="121 Spear St."
  70.                 city="San Francisco"
  71.                 country="US"
  72.                 province="CA"
  73.                 postal-code="94105"
  74.                 disabled
  75.             ></lightning-formatted-address>
  76.                 </td>
  77.                 <td style="vertical-align: top;">
  78.                     <h2 class="header" style="color: #ff8000;"><strong>Formatted Url</strong></h2>
  79.                     <h4 class="slds-text-heading_x-small">
  80.                         Absolute URLs are created if the value doesn't begin with /
  81.                     </h4>
  82.                     <div class="slds-p-around_medium">
  83.                         <p><lightning-formatted-url value="my/path" tooltip="Omit leading slash" target="_blank"></lightning-formatted-url></p>
  84.                         <p><lightning-formatted-url value="www.salesforce.com" tooltip="Use full domain name" target="_blank"></lightning-formatted-url></p>
  85.                         <p><lightning-formatted-url value="https://salesforce.com" tooltip="Use https://domain-name" label="Visit salesforce.com" target="_blank" ></lightning-formatted-url></p>
  86.                     </div>
  87.  
  88.                     <h4 class="slds-text-heading_x-small">
  89.                         Relative URLs are created if the value begins with /
  90.                     </h4>
  91.                     <div class="slds-p-around_medium">
  92.                         <p><lightning-formatted-url value="/my/path" tooltip="Include leading slash" target="_blank"></lightning-formatted-url></p>
  93.                         <p><lightning-formatted-url value="/my/path" label="Visit /my/path on this website" target="_blank"></lightning-formatted-url></p>
  94.                     </div>
  95.  
  96.                     <h4 class="slds-text-heading_x-small">
  97.                         Only http, https, and ftp protocols are supported.
  98.                     </h4>   
  99.                     <div class="slds-p-around_medium">
  100.                         <p><lightning-formatted-url value="https://www.salesforce.com" target="_blank"></lightning-formatted-url></p>
  101.                         <p><lightning-formatted-url value="ftp://public.ftp-servers.example.com/path/to/myfile.txt" target="_blank"></lightning-formatted-url></p>
  102.                     </div>
  103.  
  104.                 </td>
  105.             </tr>
  106.         </tbody>
  107.         </table>
  108.  
  109.         <br/><br/>
  110.         <!--Start RelatedTopics Section-->
  111. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  112.  
  113.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  114.  
  115.             <br/><br/>
  116.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
  117.             <div style="display:block; overflow:hidden;"> 
  118.                 <div style="width: 50%; float:left; display:inline-block">
  119.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  120.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  121.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  122.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  123.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  124.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  125.                     </ul>
  126.             </div>
  127.  
  128.             <div style="width: 50%; float:left; display:inline-block">
  129.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  130.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  131.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  132.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  133.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  134.                         <li><a href="https://www.w3web.net/tree-grid-dynamic-expand-collapse-in-lwc/" target="_blank" rel="noopener noreferrer">how to create tree grid with expanded/collapsed section for the entire row in LWC</a></li>
  135.                     </ul>
  136.                 </div>
  137.                <div style="clear:both;"></div> 
  138.                <br/>
  139.                 <div class="youtubeIcon">
  140.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  141.                 </div>
  142.     </div>
  143.  
  144. </div>
  145.  
  146.   <!--End RelatedTopics Section-->
  147.  
  148.  
  149.     </div>
  150. </lightning-card>
  151.  
  152. </template>

Create Lightning Web Component Javascript →

Step 2:- Create Lightning Web Component Javascript ➡ lwcFormattedInput.js

SFDX:Lightning Web Component ➡ New ➡ lwcFormattedInput.js

lwcFormattedInput.js [LWC JavaScript File]

  1.    import { LightningElement } from 'lwc';
  2.    export default class LwcFormattedInput extends LightningElement {    
  3.    }

Create Lightning Web Component Meta XML →

Step 3:- Create Lightning Web Component Meta XML ➡ lwcFormattedInput.js-meta.xml

SFDX:Lightning Web Component ➡ New >> lwcFormattedInput.js-meta.xml

lwcFormattedInput.js-meta.xml [LWC Meta Data XML]

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>45.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets>
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.       </targets>
  10. </LightningComponentBundle>

use the lightning formatted fields in lwc - w3web.net
 

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

What is lightning card in LWC?

A lightning-card is used to apply a stylized container around a grouping of information. The information could be a single item or a group of items such as a related list. Use the variant or class attributes to customize the styling.

Can we call lightning component from LWC?

Lightning web components can import methods from Apex classes into the JavaScript classes using ES6 import. Once after importing the apex class method you can able to call the apex methods as functions into the component by calling either via the wire service or imperatively.

What is variant in Lightning card?

Variants on a component refer to design variations for that component, which enable you to change the appearance of the component easily. ... This example uses a Lightning Design System class to apply a padding to a paragraph in the lightning:card component.

Related Topics | You May Also Like

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment