The has-error class cannot be applied to certain input elements

I am currently in the process of validating some inputs within a modal:

<div id="modal-section" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
        <h3 class="modal-title">Manage</h3>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            <i class="tim-icons icon-simple-remove"></i>
        </button>
        </div>
        <div class="modal-body">
        <div class="modal-message alert" style="display:none"></div>
        <form>
            <fieldset>
                <legend>Details</legend>
                <div class="row">
                    <div class="col-xs-12 col-sm-6">
                        <div class="form-group">
                            <label class="control-label">name</label>
                            <input type="text" class="required form-control black-content">
                        </div>
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <legend>
                    Informations
                </legend>

                <div id="questions-container">
                    <div class="card" data-id="1">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-xs-12 col-sm-8">
                                    <div class="form-group">
                                        <label for="question-name" class="control-label">description *</label>
                                        <input type="text" class="required form-control" data-id="1">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
        <div class="modal-footer">
        <button type="button" id="validate" class="btn btn-primary">save</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">close</button>
        </div>
    </div>
</div>  

Upon clicking the validate button, the following function will activate:

var missingRequired = false;

$('#modal-section .required').each(function () {
    $(this).closest('.form-group').removeClass('has-error');

    if ($(this).val() == '' || $(this).val() == undefined) {
        $(this).closest('.form-group').addClass('has-error');
        missingRequired = true;
    }
});

This function essentially examines all inputs with the required class; only the name input will turn red, while others in the questions-container will not.

Upon inspecting the HTML, it appears that the class has-error is also being added to the inputs in the questions-container, yet they are not changing color. The CSS properties on the element include:

Theme class:

.white-content .card:not(.card-white) label:not(.btn) {
    color: #344675;
}

Bootstrap class (commented within the question-container element)

.has-error .form-control-feedback, .has-error .control-label {
    color: #ec250d;
}

What could be the reason behind this behavior?

Answer №1

Based on the details provided, it seems that your CSS error rule lacks specificity. Consider updating it to:

.card .form-group.has-error label.control-label {
    color: #ec250d;
}

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

Deleting Firestore ancestor documents and sub-collections that do not exist

My goal is to tidy up my collection data. The collection I'm working with is named "teams". Within this collection, there is a sub-collection called "players". I used a basic delete query in Firestore to remove the document under ...

Displaying Table Headers on Page Breaks in Laravel PDF with Webkit Technology

Let me provide some context: I am utilizing Laravel to generate a view that is then converted to a PDF using barryvdh/laravel-snappy with the help of wkhtmltopdf, and everything is functioning as expected. However, I am encountering difficulties in stylin ...

How to stop empty numbers in angular.js

My goal is to ensure that an input with a required attribute always has some value, and if left empty, defaults to zero. <input ng-model='someModel' required> I have created the following directive: App.directive('input', fun ...

Tips for modifiying date format in React app

I'm encountering an issue where I can't modify the date format, preventing me from displaying the date on the frontend. Currently, I'm utilizing the dateformat package. import dateFormat from "dateformat"; const EditFinancialInfo ...

Tips for organizing components in jQuery Mobile

Displaying a survey creation form: <!-- HTML structure --> <div data-role="page" data-theme="b"> <div data-role="header"> <h1> Create Survey </h1> </div> <div id="main" data ...

Mastering the art of horizontal alignment in forms

So, within my render function, the following code is used: render() { <div> <form id="one"> <TextField id="t1" ... /> <Button id="b1" /> </form> <div id="empty"><div ...

most effective method to link table header to corresponding table row within this specific data organization

In my current project, I have a table component that relies on two data structures to create an HTML table: one for the table schema (paymentTableMetadata) and one for the table data (paymentTableData). To simplify the process, I have hardcoded these data ...

Strange HTML antics

On my website, I encountered an issue when trying to register without entering any information into the required fields. The errors were correctly displayed in this screenshot: https://i.sstatic.net/wrxjt.png However, after inserting random characters in ...

Testing a callback function for handling Ajax errors

When using jQuery AJAX to call a Spring REST service, it is important to verify if the error callback functionality is functioning correctly. My understanding is that the AJAX error callback is triggered when the server returns a 404, 400, or 500 error c ...

View an image in advance of uploading it and concealing any broken images

The foundational code for previewing an image before it is uploaded can be found at this link. Here are the codes: <script type="text/javascript"> function readURL(input) { if (input.files && input.files[0]) { var ...

What is the best way to fix character encoding issues with native JSON in Internet Explorer 8

When working with JSON containing Unicode text, I encountered an issue with the IE8 native json implementation. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script> var stringified = JSON.stringify("สวัส ...

Dynamically Remove One Form from a Django Formset

I have been using the following code to dynamically add a form to my formset: .html {{ form2.management_form }} <div id="form_set"> {% for form2 in form2.forms %} <table class="table table2" width=100%> ...

Instructions for utilizing float:left and list-style-type within HTML are as follows: I am currently experiencing issues with implementing the float:left and list-style-type properties in my code

I'm attempting to align a button list to the left using the float: left property and also remove list styles, but for some reason it's not working as expected. //CSS #tus{margin:5px;padding:0;width:640px;height:auto;} #tus ul{margin:0px;padding: ...

PHP mail function does not properly align HTML table outputs

After fetching data from the database and inserting it into an HTML table, everything appears fine. However, upon pressing the send button to email the content, sometimes the alignment of the HTML table is disrupted in the email. It seems like specific col ...

What is the process through which React form elements receive the event parameter?

I'm currently working on a form component that looks like this: import React from 'react'; class CommentBox extends React.Component { constructor(props) { super(props); this.state = { value: '' } this.han ...

Switching between different CSS files based on the URL using jQuery or another method

Is it feasible to apply specific styles based on the ID or load various CSS files depending on the URL you are visiting? For example: <script> if(location.href == 'http://jpftest2.tumblr.com/about'){ document.write('<style type= ...

Is there a way to store information in a kendo grid without relying on the KendoGrid toolbar?

For my testing purposes, I have created a grid setup like this: function TestCatalogDefaultsGrid() { $("#testCatalogDefaultGrid").kendoGrid({ columns: [{ field: "Catalog", template: '<select class="form-control" ...

Utilizing react js computed property to retrieve a state value: A guide

I recently developed a fading text component where the header fades in and out using transition opacity CSS and a visibility state. To simplify my code, I decided to create a fading text group component that can handle multiple fading texts at once. My goa ...

Repeated module imports

Currently, as part of my app development process, I am utilizing Parcel along with @material-ui/styles. One crucial aspect to note is that my app has a dependency on the @material-ui/styles package. Additionally, I have incorporated my own npm package, sto ...

Manage Blob data using Ajax request in spring MVC

My current project involves working with Blob data in spring MVC using jquery Ajax calls. Specifically, I am developing a banking application where I need to send an ajax request to retrieve all client details. However, the issue lies in dealing with the ...