Using AngularJS to compare values against user input to determine if they are greater or lesser

When a user inputs data into an input field, it must fall within the range of values retrieved from the database. The value entered by the user should meet either the minimum, maximum, or default value obtained from the database. For instance, if the minimum value retrieved from the database is 4500.25, any input below that amount should trigger an error message (similar to ng-messages).


View


https://i.sstatic.net/4ange.png

HTML

<div class="form-group">
    <label>Loan Amount</label>
    <div class="input-group">
        <input blur-to-currency type="text" class="form-control" name="loan_amount" ng-model="loan.loan_amount" ng-pattern="/(^(1{0,1}|([1-9][0-9]*))(\.[0-9]{1,4})?$)/" min="{{productDetails.minimum_amt}}" required>
            <span class="input-group-addon">JMD</span>
                                </div>
            <span class="tiny">Min: {{productDetails.minimum_amt | currency}}</span>&nbsp;
            <span class="tiny">Max: {{productDetails.maximum_amt | currency}}</span>&nbsp;
            <span class="tiny">Default: {{productDetails.default_amt | currency}}</span>&nbsp;

            <div ng-messages="newLoanForm.loan_amount.$error" ng-if="newLoanForm.loan_amount.$dirty">
                <div ng-message="required">
                    <span class="error-msgs">Please enter a loan amount</span>
                </div>

                <div ng-message="pattern">
                    <span class="error-msgs">Loan amount must be a numerical value</span>
                </div>
    </div>
</div>

Object Literal


https://i.sstatic.net/spfW0.png

In the above HTML, using min does not work and ng-minlength is also ineffective. I am seeking assistance in possibly creating a directive or implementing another solution to achieve the desired outcome. Thank you in advance.

Answer №1

To ensure the min function works correctly, make sure your input type is set to number. Here's an example:

<input blur-to-currency type="number" class="form-control" name="loan_amount" ng-model="loan.loan_amount" ng-pattern="/(^(1{0,1}|([1-9][0-9]*))(\.[0-9]{1,4})?$)/" min="{{productDetails.minimum_amt}}" required>

You can also check out the plunker for more details: http://plnkr.co/edit/HTBFNCLf0a6RXOzaABVU?p=preview

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

Display an array comprising of other arrays

function PersonXYZ(fName, lName) { this.lastName = lName; this.firstName = fName; this.grades = []; this.grades.push([4, 67, 5]); this.grades.push([41, 63, 5]); this.grades.push([4, 67, 55]); } var person = new PersonXYZ('John', 'Doe&apos ...

Error: The configuration object is invalid, and I am unable to deploy my server to test the bundled code

After running the webpack --mode production command to build the dist folder, I encountered an error when trying to run the server as the app is still running in developer mode. The error message displayed was: C:\Users\Bymet\Documents&bs ...

Tips for minimizing the padding/space between dynamically generated div elements using html and css

Currently, I have 4 dropdown menus where I can choose various options related to health procedures: Area, specialty, group, and subgroup. Whenever I select a subgroup, it dynamically displays the procedures on the page. However, the issue I am facing is th ...

Discover the method to adjust the position of elements, such as images, using radio buttons

I have an image positioned in a container along with 3 radio buttons. I want to make additional images appear over the main image when specific radio buttons are selected. Each button will trigger different positions for the additional images. So far, thi ...

Even though I have successfully compiled on Heroku, I am still encountering the dreaded Application Error

Looking for help with a simple express/node application to test Heroku? Check out my app.js: const express = require('express') const app = express() const port = '8080' || process.env.PORT; app.get('/', function (req, res) ...

Discovering the id of the current active tabpane is possible by using

Is there a way to retrieve the id of the currently active tab-pane every time I switch tabs on my page? Depending on which tab-pane is active (tab-pane1, tab-pane2, tab-pane3), I want to store the respective value (tab-pane1 = 1 and so on) in a variable an ...

Set the text field to be editable or readonly based on certain conditions

Is there a way to conditionally enable or disable an editable field (edit/read only)? I have tried using session role from the database to set conditions on the text field, but I am unsure of how to proceed... <?php include('session.php'); ?& ...

Guide on how to execute jasmine tests coded in TypeScript for Node.js applications

I am eager to test my express application developed in TypeScript. I am utilizing jasmine for writing test cases, webpack for bundling TypeScript files to JavaScript, and karma as the test runner. Please locate the following files: // about.service.ts - ...

Issue with delayed chaining of class addition and removal in JQuery not functioning as expected

Here is the code snippet: $(document).ready(function () { $('.current-visitors').delay(3000).queue(function () { $(this).addClass('show').delay(1000).queue(function () { $(this).removeClass('sho ...

Animating a ThreeJS Mesh using the TweenMax scaling method

Having issues trying to implement a scaling translation to my mesh[0] using TweenMax. While other animations like rotation work fine, I encounter an 'Uncaught TypeError: Cannot assign to read only property 'scale' of object '#'&apo ...

Enhancing user experience with AngularJS: Harnessing ng-Click for seamless task management on display pages

I'm struggling with my TodoList in AngularJS. I need help creating the ngClick function for the "addTodo" button. My goal is to send the entire form data to another page where I can display the tasks. Can someone guide me on what needs to be added to ...

The random quote generator or current tweet quote feature is malfunctioning

I am having trouble with a jQuery on click function that is not working to tweet the current quote. I am working on building a random quote machine and tweeting the current quote is essential. Despite successfully implementing the JSON API, I cannot seem t ...

Encountering an issue while trying to set up fs-ext with npm: error C3861: the 'fcntl' identifier cannot be

I encountered an error while trying to install fs-ext on my Windows 10 64-bit machine with Node.js v8.1.3 and npm v5.4.0. Any recommendations on how I can successfully complete the installation? PS C:\users\desktop\auth> npm install fs-e ...

Ordering request parameters in OAuth2 URL with npm passport can be achieved by following a specific method

I have successfully utilized Oauth2 strategies like Github and Twitter to log in to a web application using npm passport. Now, I am interested in logging in using the new global id authentication. You can explore it here ; it's really amazing. Whil ...

Retrieving a variable value set within a jQuery function from within an Angular 2 component

In the current project, I am facing a situation where I need to work around and initialize jQuery datetimepicker inside an Angular 2 application (with plans to refactor it later). However, when I assign a datetime value to a variable, I encounter a proble ...

Tips for formatting a phone number using regular expressions in [Vue 2]

I am currently working on creating regex code that will meet the following requirements: Only allow the first character (0th index) in a string to be either a '+' symbol or a number (0-9). No non-numerical values (0-9) should be allowed anywhere ...

Tips for displaying a Bootstrap 5 popover triggered by a select option change event

I'm using a select box with 4 options, and I have set it up so that when the user clicks on one of the options, a Bootstrap 5 popover is triggered dynamically upon the change event. Fiddle: https://jsfiddle.net/mayursutariya93/qjeg5r9b/6/ Here' ...

The marriage of ASP.NET Webforms and AngularJS

I am currently facing challenges in setting up my first ASP.NET WebApi / AngularJS application... I am attempting to access a WebAPI service (which I have developed and tested using Fiddler, confirming its functionality) from Angular, with the goal of dis ...

angular: the world of guarantees and assistance

I'm struggling to grasp the concept of promises. I understand what they are supposed to do, but when it comes to writing or debugging them, I hit a roadblock. MyController.js (function() { angular.module('WizmoApp').controller('St ...

Issue encountered in React: Unable to access object value within ComponentDidUpdate method

I'm struggling to retrieve the value from an object key. componentDidUpdate(prevProps) { if (prevProps !== this.props) { console.log("component did update in top menu", this.props.topmenudata[0]) this.setState({ ...