Prevent the button from being enabled until the file input is updated

I want to create a form with an input file for uploading photos, but I need the submit button to be disabled until the input file has a value. Additionally, there are other validations that will also disable the button.

Here is the structure of my HTML file:

<form name="form" novalidate ng-submit="submitForm();">
    <input class="btn btn-primary" type="file" accept="image/*" name="File" id="File"  style=" margin-left:5px; width: 100%;">
    <div class="form-group">
        <label class="text-left control-label">Categories: </label>
        <select class="col-xs-5 pull-right" ng-model="cat" name="cat" ng-required="true" required>
            <option value="">---Please select---</option>
            <option ng-repeat="item in Cat" value="{{item.categories_id}}">{{item.categories_name}}</option>
        </select>
    </div>
    <br/>
    <div class="form-group">
        <label class="text-left control-label">Types: </label>
        <select class="col-xs-5 pull-right" ng-model="type" name="type">
            <option value="">---Please select---</option>
            <option ng-repeat="item in Types" value="{{item.type_id}}">{{item.type_name}}</option>
        </select>
    </div>
    <br/>
    <div class="form-group">
        <label class="text-leftcontrol-label">Gender: </label>
        <select class="col-xs-5 pull-right" name="category" id="category" ng-model="gender">
            <option value="">---Please select---</option>
            <option value="0">Female</option>
            <option value="1">Male</option>
            <option value="2">Both</option>
        </select>
    </div>
    <br/>
    <div class="form-group">
        <label class="text-left control-label">*Texture: </label>
        <select class="col-xs-5 pull-right" ng-model="texture" name="texture" ng-required="true" required>
            <option value="">---Please select---</option>
            <option ng-repeat="item in Texture" value="{{item.textures_id}}">{{item.textures_name}}</option>
        </select>
    </div>
    <br/>
</div>
<div class="col-xs-5">
    <div class="form-group">
        <label class="col-md-5 control-label">*Name: </label>
        <div class="col-md-7">
            <input type="text" class="pull-right input-group inline form-control" ng-model="name" name="name" id="Name" ng-required="true" required>
        </div>
    </div>
    <br/><br/><br/>

</form>

This is how my submit button looks:

<button name="submit" type="submit" id="submitsave" class="btn btn-primary" ng-disabled="form.texture.$invalid || form.cat.$invalid || form.type.$invalid " type="button" type="button" style="margin-right:1%; width:10%; height:10%">Finish</button>          

Answer №1

If you're looking for a simple way to accomplish this task, look no further.

angular.module('app', []).controller('mainCtr', function($scope) {

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="app" ng-controller="mainCtr">
  <form name="mainform">
    <input type="text" ng-model="name" required />
    <input type="submit" value="Save" ng-disabled="mainform.$invalid" />
  </form>
</body>

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

Executing a function when a specific element is triggered within an ng-repeat in AngularJS

Hey there, I've been grappling with changing the limitTo filter on a specific list, but I'm encountering an issue: whenever I trigger the filter change, it applies to all ng-repeated categories. The function within my main controller is as foll ...

Perform a task upon clicking the JavaScript menu

Implementing dropdown menu items using a text link with JavaScript and CSS. You can view a demo here. I am looking to trigger an action when each menu item is clicked. Currently, they are not behaving as expected. HTML: <span class="inline-dropdown- ...

Customizing Material UI tooltip styles with inline CSS formatting

Currently in the process of creating a React component that utilizes the Material UI Tooltip feature. In my component, I have the need to manually reposition the Mui Tooltip by targeting the root popper element (MuiTooltip-popper). However, the Mui Toolti ...

Has anyone come across an XSLT that can effectively convert Apple Pages files into high-quality HTML?

When Apple’s word processor/DTP app Pages saves its files, it does so as zipped folders with an XML file containing the content and attachments like images stored as separate files. I am interested in converting this content into HTML format, using < ...

During operational hours, an Ajax request may cause interruptions to the website's functionality

Having an issue with a large ajax request: I am querying a PHP file that makes some cURL requests, taking 15-20 seconds to complete and then returning JSON on my webpage. It's a standard ajax request, but I found a strange bug. While the ajax query i ...

Move content off the screen using CSS3 translation

Throughout various projects, I have encountered the need to make elements on a webpage translate out of view (essentially making them fly out of the document). The idea was that by simply adding a class to the element, the CSS would take care of the animat ...

The right column in a relatively positioned layout descends as an element in the left column is revealed

Currently in the process of constructing a registration form for our website, everything is going smoothly with one minor hiccup. The form consists of two columns where users enter their information. Initially, when designing elements for the first (left) ...

What are the steps to perform an Ajax request to an online web service?

I would like to send an AJAX request to an external web service using jQuery. However, I am encountering an error and unable to receive a successful response from the server. var url = "http://www.example.com/api/convert"; var requestData = { temperat ...

Steps to deactivate two choices in a multi-select dropdown menu and visually dim those options

Hey there, I recently worked with Angular8 and Bootstrap 4. I utilized a Bootstrap multi-select dropdown, where I encountered an issue: specifically, I'm trying to disable and gray out the options for PL Marketing and CL Marketing but have been unsucc ...

Disabling form submission when pressing the enter key

Is there a way to prevent a submit action from occurring when the enter key is pressed within an ASP:TextBox element that triggers an asyncpostback upon text change? Instead, I would like it to click on another button. The Javascript function I am using wo ...

What is the best way to eliminate a specific element from a JavaScript array?

What is the best way to eliminate a particular value from an array? For example: array.exclude(value); Limitations: I must solely rely on pure JavaScript without any frameworks. ...

Tips for verifying elements using the Loop technique in a JSON array

I am new to JavaScript and I have been trying to run the following code with an expected result like this: [["00:04:12","05:54:46"],["06:06:42","12:45:22"],["12:51:11","15:56:11"]] However, my script is not working as expected. Can someone please help ...

Variation in `th` & `td` Width in Table

Is it possible to have different widths for th and td, such as 50px for th and 500px for td? To address this issue, I am utilizing datatable. To enable others to help me, here is a simple code snippet: .abc { width: 500px; } .def { width: 50px; } ...

In a Vue serverless web application, OpenLayers Map object fails to trigger events

In my Vue serverless web application, I have implemented an OpenLayers map initialized in the mounted lifecycle method. The map is populated with ImageWMS layers that are updated by various functions. After updating the parameters of these layers, I call ...

css optimizing image content for search engine visibility

My website's main page features a div with an image containing the message "contact us by calling 1 800 blabla..". I'm concerned that search engines may not be able to recognize or find my company's phone number since it is only displayed wi ...

Tips for resizing the width automatically within a container?

I am facing an issue with a container that contains 3 DIVS: left sidebar, main content, and a right sidebar. I have made the main content responsive by setting the width to width:calc(100% - 400px); (where 400px is the combined width of the sidebars). Howe ...

Issue with floating date and time not functioning properly in ICS file for Yahoo Calendar

I have set up a calendar event in Google, Apple, and Yahoo calendars for each individual customer. The event is scheduled based on the customer's address at a specific time, so there should be no need for timezone conversion. However, I encountered an ...

Getting rid of a cookie from the header in Reactjs

Currently, I'm developing an application with Reactjs and utilizing the Next.js framework. To manage user authentication, I've implemented cookies. However, I am facing a challenge when it comes to logging out users and removing the cookie. Could ...

In Internet Explorer, regardless of how much scrolling occurs, the document.body.scrollTop property will consistently be

While moving the mouse, I'm showing the value of document.body.scrollTop in the status bar. However, I have noticed that this value is consistently 0 in Internet Explorer. Why is it always 0 in IE? Is there an alternative method to determine how far t ...

The function appears to be failing to execute

I'm currently working on a dynamic search bar using AJAX to retrieve results from a database. I've noticed that when I check in the debugger, the code isn't triggering the handleSuggest() function which is responsible for updating the inner ...