1

Hi my requirement is: When select checkbox, then need to display Date as follow:

  1. When checkbox selected, Date should be year ending 1231.

Pls find my code below in controller:

    component.set("v.SFYI",ShortFirst);   // SFYI is aura boolean attribute 
    var SFYI = component.get("v.SFYI");
    // alert(SFYI);   
    // Alert working corrrectly, when checkbox selected , Value display TRUE
    if(SFYI == "true") {    
        *******Here condition is not working, not sure is this correctline
        var today = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD");
        component.set('v.today', today);
        component.set("v.date",today);
    }

Issues getting:

if(SFYI == true) --- getting issues this line, But alert showing correctly, But if condition not working can you pls assist on this Thanks

1
  • what is type of attribute SFYI in your markup? If it is boolean, if(SFYI == "true") will never be satisfied. If it is a string, then it will return true. Mar 26 '20 at 19:18
1

if SFSY is a checkbox, then you can't compare strings

Instead of this

if(SFYI == "true") {

You should do

if (SFYI) {

That is the simplest way of checking whether a variable is true or not

2
  • Thank you Sebastian......its working .
    – Sekhar
    Mar 27 '20 at 11:32
  • If it’s working, please mark the answer as accepted so others can benefit from it as well Mar 27 '20 at 14:25
-1

Or either you can drop the quotes "" . Just use if(SFYI == true) it will resolve the above issue. Thanks!!

2
  • Hi..can we hide date field When checkbox is unchecked AND when checked ..Date field should be visible ..Thanks
    – Sekhar
    Mar 30 '20 at 10:12
  • yes you can use else condition to hide it. Aug 20 '20 at 4:00

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.