Using or ||

Hey,

I have been playing with some placeholder text and was wondering if you can use the || to check if, in this example ‘courseCat’ can check more than one text query, the first example makes the placeholder text “Need boots” set for any course, regardless if it’s not winter related.
The set placeholder is shown in the photo

function placementText () {
 if (courseCat === "Winter Skills" || "Winter Mountaineering" || "Winter Climbing"){
        $w('#additionalInfoOne').placeholder = "Need boots?"
        $w('#additionalInfoTwo').placeholder = "Need boots?"
        console.log(courseCat)
    }
 else {
        $w('#additionalInfoOne').placeholder = "If relevant please inform us of any food allergies"
        $w('#additionalInfoTwo').placeholder = "If relevant please inform us of any food allergies"
    }
}

This example works but I have 8 text inputs and the code is really long, just thought I would check if i’m missing something simple in the above code.

function placementText () {
if (courseCat === "Winter Skills"){
        $w('#additionalInfoOne').placeholder = "Need boots?"  
        $w('#additionalInfoTwo').placeholder = "Need boots?"
       console.log(courseCat)
   }
else if(courseCat === "Winter Mountaineering") {
        $w('#additionalInfoOne').placeholder = "Need boots?" 
        $w('#additionalInfoTwo').placeholder = "Need boots?"    
}
else if(courseCat === "Winter Climbing") {
       $w('#additionalInfoOne').placeholder = "Need boots?"  
       $w('#additionalInfoTwo').placeholder = "Need boots?"
   }
}

Thank you!

Hi Stephen ,

Try to replace this line :

if (courseCat === "Winter Skills" || "Winter Mountaineering" || "Winter Climbing"){

with this :


if (courseCat === "Winter Skills" || courseCat ==="Winter Mountaineering" || courseCat ==="Winter Climbing"){

Hope this helps!
Best,

Mustafa

Works great @mhammouz
Thank you!

@mhammouz I have another query, is it possible to have some text that populates when the user clicks to type? for example if the click to type, there would be some text inserted before their typing input?

@stephenmccall Sure, you mean Initial text for that input. Click on the input field → setting → then below section called ( show text on load ) choose Initial text then type the initial text in the field below.

@mhammouz yes, initial text, I had tried your method before but it doesn’t seem to work. I ended up using:

$w('#additionalInfoOne').onFocus((event)=>{
            $w('#additionalInfoOne').value = "Boots - Yes/No Size"
        })
        $w('#additionalInfoTwo').onFocus((event)=>{
            $w('#additionalInfoTwo').value = "Boots - Yes/No Size"
        })