Issue with positioning the error message above the select element in the Jquery validation plugin

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

Having an issue with jQuery validation where the error message is not displaying after the select tag like it should. It's working for all other fields except the select tag. Any suggestions on how to correct this?

Javascript:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
 $('#issue_form').validate({
    errorElement: 'span',
    errorClass: 'desc',
    ignore: [],
    rules: {
      "issue[item]":{
        required: true
      },
      "issue[odometer_reading]":{
        required: true
      },
      "issue[vehicle_id]":{
        required: true
      }
    },

    messages: {
      "issue[vehicle_id]": { 
        required: "Vehicle Selection is required"
      },
      "issue[item]": { 
        required: "This Field is required"
      },
      "issue[odometer_reading]": { 
        required: "Odometer Reading is required"
      }
    },
    highlight: function(element) {
      $(element).closest('.col-sm-8').removeClass('success').addClass('has-error');
    },
    unhighlight: function(element) {
      $(element).closest('.col-sm-8').removeClass('has-error')
    },
    errorPlacement: function (error, element) {
      var elem = $(element);
      error.insertAfter(element);
    }  })
<script>

Here is my HTML code, which includes embedded ruby code for form.select:

<%= form_with(model: issue, local: true,id:"issue_form") do |form| %>

  <div class = "form-horizontal">
    <div class="form-group required">
      <label class=" col-sm-3 control-label" for="textInput2-modal-markup">Vehicle</label>
      <div class="col-sm-8">
        <%= form.select :vehicle_id, Vehicle.all.pluck( :registration_num, :id),{prompt: "Nothing Selected"},{class:"inspect_vehicle",id:"issue_vehicle_id"}%>
      </div>
    </div>
    <div class="form-group required">
      <label class="col-sm-3 control-label" for="textInput-modal-markup">Issue</label>
      <div class="col-sm-8">
        <%= form.text_field :item ,class:"form-control"%>
      </div>
    </div>
    <hr>
      <p style="float:right;">
        <%= form.submit "Save",class:"btn btn-primary" %>
      </p>
    </hr>
  </div>
<% end %>

Answer №1

By simply adding the error class after the select2-container class, I was able to successfully resolve the issue I was facing.

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

using an array as a parameter in an axios request

For the request I'm working on using Axios, I'm aiming to send an array like this [1,2,3,4]. This array will be used for a selection query in my backend. My question is whether it's better to use a GET or POST request for this purpose, and w ...

When the initial page is loaded, Jquery is successfully loaded. However, when the page is reloaded within an

Upon the initial page load, all content displays correctly. However, when attempting to reload a specific section of the page using Ajax to refresh the content, there seems to be an issue with Jquery not fully loading. Could this be due to the fact that J ...

Issues with Magento Shopping Cart upon using the browser's back button

I use a modified version of Magento 1.6.2 with significant customizations, particularly to the shopping cart template. Encountering an issue when users click the 'back' button in the browser after adding an item to the shopping cart. This proble ...

Attempting to create a TypeScript + React component that can accept multiple types of props, but running into the issue where only the common prop is accessible

I am looking to create a component named Foo that can accept two different sets of props: Foo({a: 'a'}) Foo({a: 'a', b: 'b', c:'c'}) The prop {a: 'a'} is mandatory. These scenarios should be considered i ...

Arranging divs parallelly while incorporating components within

Striving to create a layout with 3 divs side by side in an HTML document, my initial attempt resulted in this: https://i.stack.imgur.com/CpdLX.png However, I encountered an issue where the div would shift down whenever text or other objects were added: ...

Issues arising when trying to generate HTML email content from a document

Looking to send an HTML email using Python, argparse, and the command line. I want to insert content from an HTML file directly into the email body rather than just attaching the file. So far, my attempts are only resulting in the HTML file being attache ...

Initiate server side subroutine once JavaScript timer completes

The timer for the online exam countdown is created using JavaScript. If the timer reaches 0:0:00, it alerts the user and proceeds to the next webpage as shown below: function myTimer(startVal,interval,outputId, dataField){ ... var current = this.value; ...

Incorporating TypeScript into a project originally developed in JavaScript

I'm considering using TypeScript to write code for a JavaScript project. I've come to appreciate the benefits of TypeScript and am especially interested in using it for our AngularJS 1.5 project, which we plan to migrate soon. As I'm new to ...

Unusual HTML Structure (content misplaced or out of order?)

Recently, I started learning CSS/HTML in school and we just delved into Javascript. Currently, we are working on a website project. However, while trying to integrate the content with the navbar, I encountered a strange issue. When resizing to 620px or le ...

Encasing an embed code within <a href=""></a> tags

I'm having trouble getting the embed to redirect when clicked on. I tried adding href="" inside of the embed, but it didn't work. <object> <embed style="background: url(/web/css/transparent.png)" src="url.swf" type="application/x-shockw ...

Wait for Protractor until the page has completely finished loading

After navigating to https://docs.angularjs.org/tutorial, I attempted to click on '0 - Bootstrapping' under Tutorial but Protractor did not wait for the page to fully load, resulting in an Error. Error: Failed to execute 'click' on &a ...

Calculate the total number of JSON objects that have a specific value equal to

How can I use jQuery to count the number of alarms where almSeverity is "1"? The JSON response from the web service provides the following data: { "notification": "Alarm search is complete", "alarmList": [ { "almId": 1,", "almSeverity": "1" ...

The URL for react-cropper was ridiculously lengthy

I'm currently facing an issue with saving cropped images using the react-cropper library. The functionality works as expected, but the URL that is generated for the saved image is excessively long. The data package logged in the console can often exce ...

Turn off the header display for the login page

I have an angular js app with an index.html page that loads all the scripts and a default header present in all the views. Here is my index.html: <!doctype html> <html class="no-js"> <head> <meta charset="utf-8"> <title ...

Having difficulties converting the file ConvertHTMLToPDF.htm to PDF format using itextsharp in ASP and C#

Currently, I am using Itextsharp to convert HTML to PDF. The HTML file consists of multiple frames and CSS styles. The main page, ConvertHTMLToPDF.htm, includes frame1.htm, frame2.htm, and a separate style.css file. While I have successfully converted th ...

Why does starting up the Firebase emulators trigger the execution of one of my functions as well?

Upon running firebase emulators:start --only functions,firestore, the output I receive is as follows: $ firebase emulators:start --only functions,firestore i emulators: Starting emulators: functions, firestore ⚠ functions: The following emulators are ...

JavaScript code to read a .txt file

Is it possible to use JavaScript to read a text file directly with the file path provided in the code, rather than selecting the file from an open file window? ...

Sorting method in Ext JS 6.2.0 using mode

Seeking clarification on the sort([field],[direction],[mode]) method in Ext JS 6.2.0. Can someone explain the distinction between append, prepend, replace, and multi as mentioned in the documentation available at this link? I am unable to find a clear expl ...

Solving synchronization issues when updating and selecting MySql data in a Node.js environment with concurrent multiple requests

Currently, I'm using expressJS with an endpoint that connects to a MYSQL database. This endpoint executes a query to retrieve data and assigns the first result to a user by updating a specific field with the user ID. The rule is that each row can onl ...

What could be causing my class to not activate the CSS styling?

I have received a link to a stylesheet <link rel="stylesheet" href="../www.assistans.tv/css/joncss.css" type="text/css"/> Here is the CSS code: .meravsnitt { font-color: #FFF; } The HTML class being used is: <span class="mer ...