When you initiate a prevent default, both the Angular and Bootstrap UI tabs will become active simultaneously

I am facing a CSS issue while utilizing Angular UI-Tab. The problem arises when I have two tabs and need to stop tab switching based on a specific condition.

To achieve this, I implemented prevent default. However, the CSS displays both tabs as active because the click is initiated but halted midway.

Here is my HTML code:

<uib-tabset>
    <uib-tab index="1">
    <uib-tab-heading>Search</uib-tab-heading>
        <div class="PL_7 PR_7">
            <div class="clearfix">
                search tab
            </div>
        </div>
    </uib-tab>
    <uib-tab index="2" ng-click="ctrl.activateOrderBinTab()" deselect="ctrl.tabSelected($event)">
    <uib-tab-heading>Order</uib-tab-heading>
        <div class="PL_7 PR_7">
            order tab
        </div>
    </uib-tab>
</uib-tabset>

The deselect() function looks like this:

 function tabSelected($event) {
        var unsavedRows = angular.element('.dx-cell-modified');
        if (unsavedRows.length > 0) {
            $event.preventDefault();
            NotifyToastService.showError(gettext("Please save or cancel changes to the order bin to add items"));
        }
    }

However, upon testing, the output was different from what I desired:

https://i.sstatic.net/2ltQO.png

What I actually want it to be:

https://i.sstatic.net/21JnS.png

If you have any suggestions on how to fix this issue, please share with me. Thank you!

Answer №1

Utilize the $emit method to tackle the given issue.

Updates made in your code :

  1. Added a css class
  2. Eliminated the deselect functionality

I encountered a similar problem and managed to resolve it by using $emit.

Here is the updated code snippet:

<uib-tabset class="selectedTab">
    <uib-tab index="1">
    <uib-tab-heading>Search</uib-tab-heading>
        <div class="PL_7 PR_7">
            <div class="clearfix">
                search tab
            </div>
        </div>
    </uib-tab>
    <uib-tab index="2" ng-click="ctrl.activateOrderBinTab()">
    <uib-tab-heading>Order</uib-tab-heading>
        <div class="PL_7 PR_7">
            order tab
        </div>
    </uib-tab>
</uib-tabset>


 function tabSelected($event) {
        var unsavedRows = angular.element('.dx-cell-modified');
        if (unsavedRows.length > 0) {
            $event.preventDefault();
            NotifyToastService.showError(gettext("Please save or cancel changes to the order bin to add items"));
            $rootScope.$emit('selectedTab', 2);
        }
    }

$rootScope.$on('selectedTab', function (event, newTabIndex) {
        $timeout(function () {
            ctrl.selectedTab = newTabIndex;
            //this is needed to set the focus on active tab element
            //to overcome css focus styling
            angular.element(".selectedTab ul > li:nth-child(" + (newTabIndex) + ") a").focus();
        }, 1);
    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Achieving successful CSRF integration with Express.js, AngularJS, and Ngin

Having difficulty understanding how to set up csrf protection in my specific setup. My configuration includes nginx for serving static files, expressjs for handling API calls, and angularjs for the front end. All requests to /api/* are routed to express, w ...

Mastering AngularJS: Unleashing the Power of Working with Multiple ng-repeat-end Direct

Trying to comprehend how to manage multiple instances of ng-repeat-end. A table presenting 20 years of data, divided into intervals of 5 years each. Each row in the table displays data for 5 years. Below is an example of how to display the first 1-5 year ...

Issue with Bootstrap Popover not reflecting changes in Scope Variable

When a user clicks on the input field, I want to retrieve the ID of the input field, filter the object, and bind the data onto the Popover window. However, the scope is not updating from the directive. Below is the code, please point out where I may be g ...

Troubleshooting Problems with Angular Directive Parameters

I'm currently working on a directive that will receive arguments from the HTML and use them to fill in the template fields. Here's the code for the directive: (function(){ angular.module("MyApp",{}) .directive("myDirective",function(){ ...

Responsive menu is failing to respond to the click event

I'm facing an issue with my responsive menu on mobile phones. It should display two buttons - one for the navigation bar and the other to toggle the side bar by removing the classes hidden-xs and hidden-sm. However, I am having trouble getting the btn ...

The sidebar made an unexpected leap from one side to the other, with no memory of ever tampering

I'm feeling a bit overwhelmed because I can't seem to figure this out. My goal is to create a basic page layout with a header, subheader, sidebar, content pane, and footer. Everything was going smoothly until I started writing a function in my J ...

Easy fix for 3 circles (images) placed in a row with equal distance between them and perfectly aligned

I've been spending the last 3 days trying to accomplish this specific task: 3 circular images arranged horizontally with equal spacing Occupying 70% of the central screen area Height and width based on percentages for browser resizing adjustment It ...

Assist me in temporarily altering the color of menu items in a sequential manner upon the page's loading

Currently, I'm working on a website that features a subtle dark grey menu at the top of every page. The menu is built using HTML and CSS with a list structure. To highlight the corresponding menu item based on the current page, I am utilizing the ID a ...

When scrolling, use the .scrollTop() function which includes a conditional statement that

As a newcomer to jQuery, I've been making progress but have hit a roadblock with this code: $(window).scroll(function(){ var $header = $('#header'); var $st = $(this).scrollTop(); console.log($st); if ($st < 250) { ...

What is preventing HTML from triggering JavaScript when loaded inside a <div> with a script?

I'm working on creating a collapsible menu that I can easily customize on any page without the use of iframes. As someone new to web design, I have knowledge of CSS and HTML but I am currently learning JavaScript with limited experience in jQuery or A ...

Exploring the World with AngularJS and Google Maps API through ngGeolocation

Having some difficulty displaying my geolocation on Google Maps API using a marker. I am utilizing the ng controller ngGeolocation and the http://angular-ui.github.io/angular-google-maps/ Previously, I hardcoded the marker and map location without any is ...

How to align items to the left and center within a div?

How can I position the items inside a div in such a way that one element is centered and the other is aligned to the left? I attempted using flexbox, but found it difficult without introducing a hidden third element or justifying content. Another approac ...

The background image in CSS fails to display when a relative path is utilized

Currently, I am working on a JavaFX project which has the following file structure (CEP serves as the root directory): CEP +img menu.jpg +src +css_files MainMenu.css The main objective is to set the background image from the img dir ...

Styling your Kendo grid in ASP.NET MVC with custom CSS styling

I am facing a challenge with displaying two kendo grids side by side on a single view page. To modify the CSS style of a kendo grid using ASP.NET, I typically use: .HtmlAttributes(new { style="width:50%"}) However, when attempting to change more than one ...

Refresh the Angular model once the input value has been assigned using jQuery

My current situation is as follows: I have an input element whose value is being changed using jQuery's val() method. I am attempting to update the Angular model with the value set by jQuery. I tried creating a simple directive for this purpose, but ...

Conducting an AngularJS AJAX call within a Symfony2 environment and utilizing Doctrine to generate a JSON

Currently, I am working on a project involving Symfony2, Doctrine, and AngularJS. While Symfony2 and Doctrine are not causing any issues, I am facing difficulties when using an ajax request with AngularJS. The problem lies in either the data not loading pr ...

Tips for ensuring that all children within a flex-container have equal heights

I seem to be facing an issue with this problem. My goal is to ensure that all the child divs within a flex container have the same height as the tallest child div, which in this case is 100px. Additionally, I want them to be aligned at the center. I&apos ...

What is the best way to extract user input and pass it to an AJAX request URL?

Recently, I successfully completed an AJAX request using AngularJS. You can check out the code here. Everything was working perfectly until I tried to add a dynamic variable (city) to the link like this: $http.get('http://api.wunderground.com/api/KEY ...

What is the best way to dynamically search and retrieve data from a JSON object in Angular?

I am facing a challenge with my Angular (v. 1.6.3) app where I have fetched a JSON object containing stock price data. The structure of the JSON object only allows querying using brackets, with each key being a string that may include spaces, parentheses, ...

What is the best way to include Google Calendar in a div container while ensuring it is responsive?

I'm currently working on the layout of a website that features a slideshow of images at the top, followed by an embedded Google Calendar. I've encountered an issue with the responsiveness of the Google Calendar within its designated div container ...