Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Correctly highlight the current tab
Message
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
Correctly highlight the current tab
Divers
Thread ID:
01618481
Message ID:
01618481
Vues:
41
UPDATE. Got this resolved with the help of StackOverflow:

https://stackoverflow.com/questions/29659544/angularjs-ui-tabs-first-tab-automatically-selected

Hi everybody,

I have preferences form where I defined the following states:
 app.config(['$stateProvider', function ($stateProvider) {
        $stateProvider.state('home', {
            url: '/',
            controller: 'prefsAcsController',
            template: ''
        }).state('edit', {
            url: '/edit',
            controller: 'prefsAcsCrudController',
            templateUrl: '/customerAccounts/PrefsAcs'
        }).state('accountUDFs', {
            url: '/AccountUDFs',
            templateUrl: '/customerAccounts/PrefsAcs/AccountsUDFs'
        }).state('invoiceUDFs', {
            url: '/InvoiceUDFs',
            templateUrl: '/customerAccounts/PrefsAcs/InvoiceUDFs'
        }).state('confirmationText', {
            url: '/ConfirmationText',
            templateUrl: '/customerAccounts/PrefsAcs/ConfirmationText'
        });
    }]);
and in the prefsAcsCrudController I have the following:
 $scope.tabsViews = [{
                index: 1, name: 'accountUDFs',
                invalid: false, title: resourceFactory.getResource('Labels', 'xUDFs').format(resourceFactory.getResource('Labels', 'account'))
            },
                 {
                     index: 2, name: 'invoiceUDFs', invalid: false,
                     title: resourceFactory.getResource('Labels', 'xUDFs').format(resourceFactory.getResource('Labels', 'invoice'))
                 },
                 {
                     index: 3, name: 'confirmationText', invalid: false,
                     title: resourceFactory.getResource('Labels', 'confirmationText')
                 }
            ];

            function objectFindByKey(array, key, value) {
                for (var i = 0; i < array.length; i++) {
                    if (array[i][key] === value) {
                        return array[i];
                    }
                }
                return null;
            }

            $scope.previousIndex = null;

            $scope.selectView = function (viewIndex) {

                var newView = objectFindByKey($scope.tabsViews, 'index', viewIndex);

                if ($scope.previousIndex != null) {
                    $scope.tabsViews[$scope.previousIndex - 1]["invalid"] = $scope.form.$invalid;
                }

                $scope.previousIndex = viewIndex;
                if (newView) {

                    var viewName = newView["name"];
                    $state.go(viewName);
                }
            };
and in the chtml page I placed:
 <div class="col-lg-2 col-md-2 panel-container">
                        <tabset vertical="true" type="pills">
                            <tab ng-repeat="tab in tabsViews" select="selectView(tab.index)"
                                 class=" {{tabsViews[tab.index-1]['invalid'] ? 'invalid-tab': 'valid-tab' }}">
                                <tab-heading>{{tab.title}}</tab-heading>
                            </tab>
                        </tabset>
                    </div>

                    <div class="col-lg-10 col-md-10 panel-container">
                        <div data-ui-view data-autoscroll="false"></div>                    
                    </div>
All seems to work nicely.

Now, in the Customer Accounts/Invoices/User Defined I placed the following
 <div class="col-md-12">
                <div ng-bind-html="noInvoicesUserDefined"></div>
            </div>
where noInvoicesUserDefined is this:
 $scope.noInvoicesUserDefined = resourceFactory.getResource('Messages', 'noUserDefinedConfiguredX').format(
         "<a href='/CustomerAccounts/PrefsAcs#/InvoiceUDFs'>" + resourceFactory.getResource('Labels', 'invoices') + "-" +
         resourceFactory.getResource('Labels', 'preferences') + "</a>");
It also works nicely and automatically the second tab is selected when I click on the link. This is exactly what I want. The only problem here is the active class is still on the very first tab (e.g. I see the UDF for Invoices but on the left I see Account User Defined highlighted tab).

Do you see what should I fix to make the invoices tab to be highlighted when I access it this way?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform