Page 1 of 1

How to specify URL to a tab

Posted: 2018-11-15 12:49
by sjohn
I have a question much like the "add a next button to a form"

I can specify a URL that directs to a detail-view.
Could be something like this : http://eksempelsite.dk/engdr/eng_firms_ ... ectedID=26

This detail view has two tabs.
The tab "Home" is the default.
If you hover the home, or ( mouse right click - copy link address ) you will see :
http://eksempelsite.dk/engdr/eng_firms_ ... tomer-info

If you hover the other tab ( additional info ) you will see : http://eksempelsite.dk/engdr/eng_firms_ ... dress-info

There could have been more tabs in a detail view.

How do you specify a/the URL that directs to the detail view, but also to a specific tab????

And should there be done something in a hook.

Re: How to specify URL to a tab

Posted: 2018-11-15 17:06
by pbottcher
Hi,
I'll try to give it a shot.

I think, as the page is recreated with tabs after the initial call, you will not be able to get directly to a tab, but if you use the information in the URL and use javascript, you should be able to extract the "#...." information which indicates to which tab you want to navigate and then you should be able to activate this tab.

You can activate your tab via

Code: Select all

$j('.nav-tabs a[href="'+TABINFO+'"]').tab('show');

where TABINFO is your "#...." like the #address-info.

Hope it helps

Re: How to specify URL to a tab

Posted: 2018-11-16 07:53
by sjohn
Hello pböttcher

Thank you for responding.

I guess the URL should still be the one shown - but - how/where to use the code you have given?

Re: How to specify URL to a tab

Posted: 2018-11-16 08:21
by pbottcher
put it in the hooks/eng_firms-dv.js file (if it exisits, or create it). You may need to test if the tabs are already loaded, not sure right now in which order that happens, can't test it now.

Re: How to specify URL to a tab

Posted: 2018-11-16 09:19
by sjohn
Hello pböttcher
Thanks for quick response.

I created and uploaded eng_firms-dv.js
The content I have tried with is this :

$j('.nav-tabs a[href="'+TABINFO+'"]').tab('show');

and this

$j(function(){
$j('.nav-tabs a[href="'+TABINFO+'"]').tab('show');
});

The URL I use is this : http://eksempelsite.dk/engdr/eng_firms_ ... dress-info

It seems to have no effect

Re: How to specify URL to a tab

Posted: 2018-11-16 10:25
by pbottcher
Hi,

can you try $j('.nav-tabs a[href="#address-info"]').tab('show');

Re: How to specify URL to a tab

Posted: 2018-11-16 11:08
by sjohn
Hi

I tried it - but still no effect

Re: How to specify URL to a tab

Posted: 2018-11-16 11:15
by sjohn
Hello again.

made a mistake.
The last one functions

Re: How to specify URL to a tab

Posted: 2018-11-16 11:19
by sjohn
But of course it now directs to that tab always. I guess you wanted to know about the syntax.

Re: How to specify URL to a tab

Posted: 2018-11-16 11:31
by pbottcher
Hi, you will need to check the calling url, otherwise it will always redirect.

Re: How to specify URL to a tab

Posted: 2018-11-16 11:47
by sjohn
Hi. Okay. You mean that I have to check if the url contains #customer-info and then use/set $j('.nav-tabs a[href="#customer-info"]').tab('show');

and check if url contains #address-info" and then use/set $j('.nav-tabs a[href="#address-info"]').tab('show');

Right?

Re: How to specify URL to a tab

Posted: 2018-11-16 11:52
by sjohn
In case I only have two tabs I need only check for the second tab - i guess.
And in case I have 3 tabs, I only have to check for the last 2 ?
Because the first tab is the default.

Re: How to specify URL to a tab

Posted: 2018-11-16 11:56
by sjohn
In this specific case, I should only have to check for the #address-info" and then use/set $j('.nav-tabs a[href="#address-info"]').tab('show');

Is this correct - and how should the check look like?

Re: How to specify URL to a tab

Posted: 2018-11-16 13:12
by pbottcher
Hi,
basically correct, but I would do it rather generic.

Something like:

Code: Select all

	var url_string = window.location.href;
	var idx=url_string.indexOf("#");
	if (idx > 0) {
		$j('.nav-tabs a[href="'+url_string.substring(idx)+'"]').tab('show');
	}
would check if the URL contains the # sign and show the according tab if it was specified in the URL. So this could be used for any amount of tabs.

Re: How to specify URL to a tab

Posted: 2018-11-16 14:18
by sjohn
Hello pböttcher

You really are a super hero !!!

This functions, it is generel, and it is in a hook. This can be used for all views and without changing the code. And there is no special in it - if the detail-view is shown by a link ( with the ID ) then it is the URL shown on tab mouseover. Perfect.
Thank you