Step 5: Customizing the Experience

Our search bar is looking a bit empty and could use some placeholder text. Conveniently enough, the property is called placeholderText. Let’s update the property in our SearchBar component:

this.addComponent("SearchBar", {
                container: ".search-bar",
                placeholderText: "Questions? I got Answers"
            });

Refresh the page and the text should be in the search bar automatically!

Our final HTML file will look like this:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Search Test Experience</title>
    <!-- Answers CSS-->
    <link rel="stylesheet" type="text/css" href="https://assets.sitescdn.net/answers/v1/answers.css" />

    <!-- Answers Layout styling -->
    <style>
        .answers-layout {
            max-width: 50rem;
            margin: auto;
        }
    </style>

    <!-- Answers JS-->
    <script src="https://assets.sitescdn.net/answers/v1/answers.min.js"></script>

</head>

<body>
    <div class="answers-layout">
        <div class="search-bar"></div>
        <div class="spell-check"></div>
        <div class="direct-answer"></div>
        <div class="universal-results"></div>
        <div class="location-bias"></div>
    </div>
</body>

<script>
    ANSWERS.init({
        apiKey: "3517add824e992916861b76e456724d9",  //sample test experience
        experienceKey: "answers-js-docs", //sample test experience
        businessId: "3215760",  //sample test experience
        experienceVersion: "PRODUCTION",
        onReady: function () {
            // init components
            this.addComponent("SearchBar", {
                container: ".search-bar",
                placeholderText: "Questions? I got Answers"
            });
            this.addComponent("SpellCheck", {
                container: ".spell-check"
            });
            this.addComponent("DirectAnswer", {
                container: ".direct-answer"
            });
            this.addComponent("UniversalResults", {
                container: ".universal-results"
            });
            this.addComponent("LocationBias", {
                container: ".location-bias"
            });
        }
    });
</script>

<script
    src="https://assets.sitescdn.net/answers/v1.5/answers.min.js"
    onload="ANSWERS.domReady(initAnswers)"
    async
    defer
></script>

</html>
light bulb
Want to learn more?

To learn more about the components on our page and the properties they use, check out the following:

SearchBar
SpellCheck
DirectAnswer
UniversalResults
LocationBias

Check out our component library for adding new components.

Feedback