Validating the length of form inputs and selected items from a dropdown menu

I have the following form and I am attempting to validate its states as follows:

themeName is required and should have a minimum of 4 characters. themeLangFrom selected value cannot be the same as themeLangTo (and vice versa).

I want to display a span error message under each field that is invalidated.

I have tried doing it this way, but I am having trouble resolving it with select inputs.

Can someone please tell me the correct way to do it?

Form code:

<ul class="nav nav-pills pull-right">
    <li><a href="" ng-click="showModalNewTheme()">Close form</a></li>
</ul>
<h3 class="text-muted">Add New Theme</h3>

<form role="form" name="addThemeForm" id="addThemeForm" >
    <div class="form-group">
        <label for="themeName">Theme name:</label>
        <input id="themeName" type="name" required class="form-control" ng-minlength="4" ng-model="newtheme.name"  placeholder="Enter Theme Name">
        <span class="formValidationError" ng-show="addThemeForm.themeName.$error">Enter valid e-mail</span>
    </div>


    <div class="form-group">
        <label for="themeLangFrom">Language from:</label>
        <select  id="themeLangFrom" required class="form-control" ng-options="language as language.name for language in languages" ng-model="newtheme.langFrom" >
            <option  value="">{{language.name}}</option>
        </select>
    </div>


    <div class="form-group">
        <label for="themeLangTo">Language to:</label>
        <select id="themeLangTo" required class="form-control" ng-options="language as language.name for language in languages" ng-model="newtheme.langTo" >
            <option  value="">{{language.name}}</option>
        </select>
    </div>

    <input ng-click="addTheme(newtheme)" ng-disabled="!addThemeForm.$valid" type="submit" value="Add New Theme" class="btn btn-success btn-block btn-lg">
</form>

Answer №1

To confirm that themeLangFrom and themeLangTo are not the same, a unique custom directive must be created.

One option is to utilize the ui-validate directive from angular-ui (http://angular-ui.github.io/ui-utils/) or alternatively:

Create your own... Look at existing examples of password validation directives but remember in this case the values should not match like they do in passwords.

Examples can be found here: password-check directive in angularjs

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

What are the potential reasons for the failure of multiple GET requests in a Protractor test

I'm currently running a protractor test in the Amazon EC2 environment using the PhantomJS browser. Although it is generally not recommended to use PhantomJS with Protractor, I have no other choice at the moment. The tests always run smoothly in a Win7 ...

stopping action when hovering

Looking for some assistance with my javascript function that scrolls through an array of images on a set interval. I want to enhance it by pausing the rotation when hovering over any of the images. Javascript (function() { var rotator = document.getE ...

The MUI Select component requires two clicks to open its menu if another Select component's menu is already open

I have been developing an application with two dropdowns (Select components) positioned next to each other, denoted as A and B. When A is open and the user intends to click on B to open it, I observed that in the default behavior of material UI, the user ...

Tips for integrating a computed function with v-bind and v-on in Vue.js

Although it may seem like a simple example, I am just starting to learn Vue. I believe the error is occurring where I have indicated. I am attempting to call a function from a computed method. There doesn't seem to be an issue when writing the code d ...

Following the build process with the --prod flag in Ionic 3, users may encounter a situation where

Encountering an issue only when using --prod on Android phones. Strangely, touching anywhere triggers the event that should be fired at that specific location, causing the content to suddenly appear. I came across information suggesting a conflict between ...

jquery blur function not triggering properly

I am not very familiar with jquery and javascript. Below is the code I have written for an input text field where I want to use blur function for validation: <div class="form-row form-input-name-row"> <label> <span>Full name& ...

Looking for a simple method to display a popover using conditional if/else statements?

On my website, I am utilizing JavaScript to determine the user's Facebook status. This includes checking if the user is already logged in and has allowed our app, if they are logged in but haven't authorized our application, or if they are not lo ...

Creating a directive in AngularJS to automatically populate select options with custom values

As someone who is relatively new to creating directives, I am looking to develop a directive that will assist me in my application. What I aim to achieve is a select element directive that comes pre-populated with options and is self-contained. All I need ...

Issue with retrieving attributes in the directive

One of the challenges I encountered is incorporating a directive that wraps the jQuery FullCalendar plugin into my project. Here is how I implement the directive: <div sg-calendar format-column-header-month='dddd' format-co ...

Transform a section of text into JSON format to utilize in DataTables

Currently, I am utilizing DataTables and Leaflet in my project. The data displayed below needs to be represented on my screen using Datatables. Specifically, I would like to convert it into JSON format without including the {....} part. How should I proc ...

Convert the numerical values from an array into an input field format

Currently, I have two inputs and an array with two number positions. The v-model in each input corresponds to a value in the array. Whenever a change is made in either input field, it reflects on the corresponding position in the array, which works perfect ...

Despite setting allowHalfOpen to True, Node.js: Client still disconnects from Server

I've been working on a Node.js script that involves creating a server if a specific port is available, or connecting to an existing server if the port is already in use. To achieve this, I am using a recursive approach based on a reference from this l ...

Creating expandable card components with React and CSS using accordion functionality

I am currently working on creating a card that will expand its blue footer when the "view details" link is clicked to show lorem text. However, I am encountering an issue where the blue bottom of the card does not expand along with the lorem text. You can ...

Manipulating Data in AG-GRID with AngularJS: A Guide to External Editing

Currently, I'm in the process of developing a single-page application that utilizes AngularJS, UI-Router, and AG-GRID. However, I've encountered an issue with updating AG-GRID's data from an external form. Here is a breakdown of the problem ...

Issue encountered while invoking the jQuery html method

Embarking on my first adventure with javascript + jQuery, creating a basic page but running into errors. I've gone through the code multiple times and still can't seem to find the issue. Below is the error message I am encountering: The complet ...

Transform the string response in a websocket message into JSON format

When receiving a websocket message, I often encounter a response in the form of a string like this: odds.1:[{"id":1,"marketType":10,"name":"Double chance","status":"HandedOver","specifiers":"","Outcomes":[]},{"id":2,"marketType":11,"name":"Draw no bet", ...

Vue table does not update when checkbox is unchecked

I am currently utilizing Daisy UI and basic VUE to create a checkbox functionality. When I check the checkbox, it successfully filters the table entries; however, when I uncheck or check another checkbox, the filter does not refresh again. Below is my tab ...

Utilizing conditional statements like if/else and for loops within a switch statement in JavaScript allows for

I am currently developing a request portal that involves dynamic checkboxes, labels, and textboxes that are dependent on an option list. As a beginner in javascript, I am facing challenges with creating conditional statements. I have managed to make progr ...

Adding a query parameter to a dynamic route in NextJS

In my NextJS application, I have implemented a language selector that is displayed on every page. The goal is to change the current URL by adding a query parameter lang=en when a new language is selected. The function responsible for updating the URL look ...

Guide to transferring parameters from one function to another in Javascript

For my automation project using Protractor and Cucumber, I have encountered a scenario where I need to use the output of Function A in Function B. While I was able to do this without Cucumber by extending the function with "then", I am facing difficulties ...