Problem

Create a Lightning Web Component (LWC) to conditionally render inupt fields on the screen.

The component needs to display two sets of fields based on the javascript variable isIndividual.

Complete the provided practice example to conditionally render input fields on the component.


Instructions

  • The isIndividual is a public variable (@api) declared in the javascript file.
  • If isIndividual is set to true, show only first name and last name fields
  • If isIndividual is set to false, show only the name field.

Sample output

1. When isIndividual is set to true

lwc conditional fields individuals

2. When isIndividual is set to false

lwc conditional fields company

Note : This exercise introduces you to writing a simple LWC component that dynamically shows fields based on a javascript variable. Focus on meeting the requirements, and feel free to validate your code using the execute button.

Refer to the official LWC documentation link for more details on conditional rendering in LWC.

To learn more about lightning web components, click here to visit the lightning web components developers guide

  • <>conditionalRendering.html
  • JSconditionalRendering.js
  • #conditionalRendering.css
Loading...
show full screen editor