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

New Thread from Category doesn't preselect Category from dropdown #375

Open
Ultimater opened this issue May 8, 2017 · 2 comments
Open

Comments

@Ultimater
Copy link
Sponsor Member

This isn't a feature request per se, as it's the expected functionality.

Go to https://forum.phalconphp.com/category/21/beginners for example (as it has the most threads).
Then click "Start a Discussion" on that page, there's a "Category" dropdown to choose the category again. Expected behavior is it should pre-select "Beginners" in this case. I'd like to suggest use the referrer to determine what to highlight. This JavaScript has been tested thoroughly and would get the job done:

try{
  (function(){
    var r = document.referrer, m = r.match(/\/category\/(\d+)\/([^\/]+)/), e = document.getElementById("categoryId"), o = e.options;
    for(var i=0;i<o.length;i++)if(o[i].value==m[1] && o[i].text.match(/(\w+)/)[1].toLowerCase() == m[2].match(/(\w+)/)[1].toLowerCase())e.selectedIndex=i;
  })();
}catch(E){}
@Jurigag
Copy link
Contributor

Jurigag commented May 8, 2017

Good idea, i like this. Could maybe avoid somehow usage of js and handle it in php.

@Ultimater
Copy link
Sponsor Member Author

If we're aiming at a PHP solution, we could read $_SERVER['HTTP_REFERER'] and parse it using a similar regular expression, then add a selected to the option to select. We could also change the navigation a bit and ditch the refe(r)rer altogether by creating a different create new topic link which we can extract the category from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants