Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Re-initialize Answers After Initial Error #445

Open
creotutar opened this issue Jan 13, 2020 · 2 comments
Open

Unable to Re-initialize Answers After Initial Error #445

creotutar opened this issue Jan 13, 2020 · 2 comments

Comments

@creotutar
Copy link
Contributor

creotutar commented Jan 13, 2020

On Answers v11, cannot run ANSWERS.init successfully after getting an error from any previous ANSWERS.init. Specifically the error when the given container class does not exist.

Steps to recreate:

  1. Open a page without a div element with class ".test"
  2. Load Answers Script: In Dev Tools Console
(function(document, tag) {
    var scriptTag = document.createElement(tag), // create a script tag
        firstScriptTag = document.getElementsByTagName(tag)[0]; // find the first script tag in the document
    scriptTag.src = 'https://assets.sitescdn.net/answers/v0.11.1/answers.js'; // set the source of the script to your script
    firstScriptTag.parentNode.insertBefore(scriptTag, firstScriptTag); // append the script to the DOM
}(document, 'script'));
  1. ANSWERS.init with missing element and get error
ANSWERS.init({
          apiKey: 'TODO',
          experienceKey: 'TODO',
          onReady: function () {
            ANSWERS.addComponent('SearchBar', {
              container: '.test',
            });
          }
        });
  1. Try ANSWERS.init on any element that exists and it will not throw an error or populate the container
    4.5. Inserting the missing element also does not work
var something = document.createElement('div');
something.addClass('test');
document.body.appendChild(something);
ANSWERS.init({
          apiKey: 'TODO',
          experienceKey: 'TODO',
          onReady: function () {
            ANSWERS.addComponent('SearchBar', {
              container: '.test',
            });
          }
        });
@rosiegrant
Copy link
Contributor

@creotutar sorries i might just not understand this -- when you're setting up the Answers experience, you're calling the Answers init multiple time on the same page? "cannot run ANSWERS.init successfully after getting from any previous ANSWERS.init"

@creotutar
Copy link
Contributor Author

yes, calling ANSWERS.init once, getting an error, fixing the error, and then calling the same ANSWERS.init again does not correctly init answers

@tmeyer2115 tmeyer2115 self-assigned this Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants