Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
in Q2A Core by
I'm not sure if this is a bug, but heck if it's not, it's very annoying. Basically, if permissions are set for registered users to answer questions and if in the "Viewing" options in admin the "Show answer form immediately: is set to Always", then whenever someone is logged in and they click on a question, the page immediately jumps them to the answer box below the question - not the top of the page. This is very annoying and terrible user interface, because someone can't possibly answer the question, until they read the question. If the question is a bit long, they need to scroll back up to read the question.

I imagine this functionality has something to do with jquery or javascript? How do we prevent this from happening? When someone clicks on a question link from a question list, it should be like any web page they click on and the viewing should start at the top of the page. It shouldn't jump to some location on the page beneath the question.

Where in the code is this "jump" feature coded?
Q2A version: 1.5 beta 2
Which editor type are you using? And are you clicking on the question title? If you click e.g. "answered X hours ago" it will jump to the specific answer.
I'm using the text editor. I'm just clicking on the question link in the question list. This only happens when you  have the "Show Answer Form immediately: is set to always". This is some sort of JS bug in Q2A, which I can't seem to find the code to fix. Basically what seems to be happening is that  if the answer form is set to always show, then when some goes to a question page some variable is already set on the page, so that the page jumps immediately to the answer form.
FYI, I just found this in the qa-page-question-view.php code (line 723) in the comments: If $loadfocusnow is true, the form will be loaded and focused immediately.

So I guess it's an issue of setting the $loadfocusnow variable? If this is true, I recommend always setting this false, because focusing the form is plain silly from a user perspective as someone needs to read a question before they can answer it. Will test the above and report back.
OK, I've gone thru the code on the qa-page-question.php (230-251) - //    Prepare content for an answer being edited (if any) or to be added -
This seems to call the function function qa_page_q_add_a_form() on line 719 on qa-page-question-view.php -

This is where the focus action happens. I've tried many options but can't fix this. Maybe gideon can chime in with a potential fix.

From my perspective, this is surely a bug, if only because it makes no sense from a user perspective.

If the "Show Answer Form immediate: is set to always" - then the code is assuming that the Answer Form should be focused on page load, as if someone had clicked the Answer link (if the Answer form was not set to always). This is a incorrect. The answer form should not be focused unless someone clicks on the Answer link, even in the case where the Answer Form is set to Always show. The reason is simple: people need to read a question before they can answer it and by focusing the Answer form immediately if its set to Always show, one jumps to the answer form without being able to even read the question.
Thanks - will check into this for the final 1.5 release.

Please log in or register to answer this question.