"Is there a way to activate the md-button using the controller even if it has an ng-disable expression applied

I have an md-button within my form that I've disabled using an ng-disable expression. Everything is functioning correctly. However, now I am looking to enable the button based on a specific condition from the controller. Here's how I attempted to set it:

vm.verifyMobileForm.$invalid = true;

Unfortunately, this approach did not work for me.

Below is the element in question:

<form name="verifyMobileForm" novalidate>
    <md-input-container class="md-block" md-no-float>
        <input type="mobile" id="mobile" ng-value="{{vm.form.mobile}}" 
                name="mobile" ng-model="vm.form.mobile" 
                placeholder="Your Mobile number" 
                ng-pattern="/^[789]\d{9}$/" maxlength="10" required
        />
        <div ng-messages="verifyMobileForm.mobile.$error" role="alert" multiple>
            <div ng-message="required">
                <span >Mobile number is required</span>
            </div>

        </div>

    </md-input-container>
    <div class="dialog-demo-content" layout="row" layout-wrap layout-margin layout-align="center">
        <md-button type="submit" 
              class="md-raised md-accent submit-button" 
              ng-disabled="verifyMobileForm.$invalid || verifyMobileForm.$pristine" 
              ng-click = "vm.checkMobile($event, document.getElementById('mobile').value)"
        >
            Next
        </md-button>
    </div>
</form>

And here is the snippet from my controller where I tried to set it to true:

(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.verify-mobile')
        .controller('VerifyMobileController', VerifyMobileController);

    /** @ngInject */
    function VerifyMobileController($scope,dataservice,msApi, $state,$mdDialog)
    {
        var vm = this;
        vm.form = {};
        var getMob = dataservice.getData();
        if(getMob){
            vm.form.mobile = getMob[1].mobile;
            vm.verifyMobileForm.$invalid = true;
        }
    }
}();

Answer №1

Are you looking to activate the Button based on a specific condition? If so, consider implementing something like this:

ng-disabled="(verifyMobileForm.$invalid || verifyMobileForm.$pristine) && ACTIVATEBUTTON"

...

In your controller, you have the ability to enable the button even if the form is invalid by using:

$scope.ACTIVATEBUTTON = true;

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

Refreshing the view in AngularJS after making an HTTP request can be tricky. One common issue is receiving the error message "$rootScope

My goal is to load data when my app starts, but the view loads faster than the HTTP request. I need to refresh my view once the data is properly loaded because it defines how the view should be displayed. I've tried using $rootScope.apply from inside ...

Adding an item to an array in Angular 2 using JavaScript!

In my Angular2 form, I have a field that consists of an array of objects. I've successfully created a table with a Delete Row button for each row and an Add Row button using the push() and slice() methods in JavaScript. However, there's a major ...

Exploding particles on the HTML5 canvas

I've been working on a particle explosion effect, and while it's functional, I'm encountering some issues with rendering frames. When I trigger multiple explosions rapidly by clicking repeatedly, the animation starts to lag or stutter. Could ...

Alternative solution to avoid conflicts with variable names in JavaScript, besides using an iframe

I am currently using the Classy library for object-oriented programming in JavaScript. In my code, I have implemented a class that handles canvas operations on a specific DIV element. However, due to some difficulties in certain parts of the code, I had t ...

Transforming Observable into a Promise

Is it considered a best practice to convert an observable object to a promise, given that observables can be used in most scenarios instead of promises? I recently started learning Angular and came across the following code snippet in a new project using ...

Discover a technique to display every individual "echo" statement from PHP in sequence, rather than waiting for the entire script to finish executing

I have developed a PHP script that takes some time to execute and displays multiple "echo" statements as the progress is being made. The script connects to an FTP server, deletes all contents, and then uploads new files. Everything is functioning correctly ...

Determining the date based on user input

I am currently working on developing a Date Calculator widget that can generate dates based on user inputs to various fields. The idea is to allow users to find the date of an event that occurred a certain number of months/years/days ago by simply inputtin ...

Dropdown menu does not appear upon hovering over an item

I have been trying to create a menu that appears when hovering over #navigation-region. Below, you can see the HTML, CSS, and JavaScript code: The JavaScript is simply for adding the active class on the #navigation-region element. In the CSS, there is a s ...

Utilizing Isotope JS on your Wordpress website

I'm in the process of integrating the .js plugin, Isotope, into my Wordpress installation. It should be positioned at the bottom of this page: To achieve this, I am referring to an example on codepen: https://codepen.io/desandro/pen/mEinp The script ...

Angular fire generator error: Peer validation failure

Whenever I try to execute npm install -g grunt-cli, I encounter the following error message npm ERR! peerinvalid The package generator-angular does not meet the peerDependencies requirements of its siblings! npm ERR! peerinvalid Peer <a href="/cdn-cg ...

"Prevent users from taking screenshots by disabling the print screen key

Can someone help me figure out how to prevent users from taking a screenshot of my website by disabling the print screen key? Here's the code I've tried so far: <SCRIPT type="text/javascript"> focusInput = function() { document.focus() ...

What is the best approach for transforming repetitive React code patterns into a reusable component or object?

Take a quick look at this section without overanalyzing it, and focus on the similarities among each group. // LOADING VENDORS const [loadingVendors, setLoadingVendors] = useState<boolean>(true); const vendorsErrorTimeout = useRef<NodeJS.Timeout|n ...

What is the best practice for retrieving data in a Reactjs application?

I've been working on a Reactjs app and have run into an issue regarding data fetching from Firebase. I'm unsure whether it's more efficient to fetch data in the root component (App.jsx) or in individual components. Currently, I have collect ...

How can default props be set for a nested object in Vue?

Here's how I've defined my props: myHouse = { kitchen:{ sink: '' } } I attempted to set the default props like this, but it didn't work as expected. props: { house: { type: Object, default: () => { ...

Only show the directive methods when using "ng-if"

I am facing an issue with the Opentoke Library directive, particularly when I use the ng-if. The reason for implementing the ng-if is that WebRTC is not supported on IOS devices, so it displays an alert after the DOM has loaded. <div class="opentok" ng ...

Bidirectional communication between server and client using socket.io in node.js

I'm currently working on developing a server code in node.js where the client, running on a browser, will send data to the server when a specific ".on" event occurs. The task on the server side is to receive this incoming data from the client and then ...

Adding an item to a JSON array in Angular

I'm having trouble adding a new item to the roleList JSON array. I've tried using push/concat, but it doesn't seem to update the roleList array. Any suggestions on how to resolve this? // The javascript : function RoleListCtrl($scope) { ...

A guide to increasing a loop counter in Vue

Having trouble looping through a specific group of objects in a multi-object array? Take a look at the code below: <template> <div> <h1>My Test App</h1> <button v-on:click="getHockeyData">Get Team Data< ...

Exploring the world of Bootstrap Twitter 3.0 alongside the wonders of Knockout

When utilizing Twitter Bootstrap, the validation classes like has-error or has-warning must be added to the wrapping form-group element to style both the input and its label. However, Knockout-Validation directly adds the class to the input element itself. ...

Creating a seamless login experience using Hapi.js and AngularJS

It appears that I may need some clarification, here are the Docs for hapi I have this set up on the backend with hapijs and node.js. server.route({ method: 'POST', path: '/login', handler: function(request, reply) { USER: re ...