I'm currently looking to change the required attribute based on multiple scenarios. So, I have a created input field with the required attribute as newAccRequire but by default, it's getting the true value.

But if I hardcoded directly required="false" it's working as expected.


<aura:attribute name="newAccRequire" type="String" default="false"/>
<lightning:input aura:id="createNewAcc" type="String" name="inputAccName" 
                                 label="" value="{!v.leadRecord.Company}" 

I have checked any references for this field on controller or helper, but I'm not using this field. Any idea why the field became mandatory automatically.

I have tried the solution but it's breaking in some situations. still, it's setting as true in some situations. any idea?

Screenshot: enter image description here

My JS controller


1 Answer 1


The attribute you are referencing should be of type "Boolean" for representing true/false values. In JavaScript, all non-empty strings are truthy, so if you use the String attribute type, it will be behave differently than if you declare the attribute as a Boolean type.

  • 1
    Nice answer, I just added a bit from an answer I was writing. Welcome to SFSE! If you haven't yet, please feel free to read about How to Answer and take the tour. Looking forward to seeing future contributions from you.
    – sfdcfox
    Oct 27, 2021 at 19:38
  • Thank you, @sfdcfox! I have lurked and used several of your contributions to help solve my problems in the past. I hope to gain even more insight by interacting directly on SFSE. Cheers! Oct 27, 2021 at 19:43
  • Your solution worked partially, could you please look in to this
    – Pavan tej
    Oct 27, 2021 at 20:05
  • 1
    @Pavantej you're setting the string 'false' in your attribute (it has quotes). You should use the Boolean value false (no quotes).
    – sfdcfox
    Oct 27, 2021 at 20:31
  • 1
    component.set("v.newAccRequire",false); specifically. Remember when using strings with any length they will be evaluated as truthy in javascript. Oct 27, 2021 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.