Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
817 views
in Q2A Core by
It would be nice if the "related questions" that would show after someone enters their question initially would show up as "tips" when typing the question. I see that this can be done on the full "Ask a question" page but I would like it to be present in the ask widget.
Q2A version: 1.5.2

1 Answer

+3 votes
by

I also wanted to make add search autocomplete.
I found out that autocomplete option is already built in the code, and is used when someone is asking (not searching) a question on the ask page.

I added a search box to my theme's hearder (you may alrady have your search box somewhere)

<input type="text" placeholder="Find your answer..." name="q" onkeyup="qa_title_change_search(this.value);" autocomplete="off" required>

Then I added the a span which will display the suggested questions just below the search box:

<span id="similar_search"></span>

 

Now I went to qa-ask.js and based on this function "qa_title_change"(which is used for the autocomplete while asking a question) I careated the function: "qa_title_change_search"

function qa_title_change_search(value) {
    qa_ajax_post('asktitle', { title: value }, function (lines) {
        if (lines[0] == '1') {
            if (lines[1].length) {
                qa_tags_examples = lines[1];
                qa_tag_hints(true);
            }
 
            if (lines.length > 2) {
                var simelem = document.getElementById('similar_search');
                if (simelem)
                    simelem.innerHTML = lines.slice(2).join('\n');
            }
 
        } else if (lines[0] == '0')
            alert(lines[1]);
        else
            qa_ajax_error();
    });
 
    qa_show_waiting_after(document.getElementById('similar_search'), true);
}
 
If you want to change the line displayed before the suggested questions, you can look for "ask_same_q" in qa-lan-question.php (be default it is: "Before proceeding, please check your question was not asked already:")
...