Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relocate error labels using jQuery validation

So I'm using jQuery validation and have managed (despite some out of date documentation) to get a group of required radio boxes working. The problem is the plugin is appending the error label directly after the first radio (the first of that group that has the required class).

With this in mind is it possible to set a custom location for each error label?

For reference this is the HTML:

<tr>
    <td width="200">
        <label>Title2 *</label>
    </td>
    <td width="505">
>>>     <label><input type="radio" class="required" name="Title2" value="Mr" /> <!-- ERROR APPEARS HERE -->Mr</label>
        <label><input type="radio" class="required" name="Title2" value="Miss" />Miss</label>
        <label><input type="radio" class="required" name="Title2" value="Mrs" />Mrs</label>
        <label><input type="radio" class="required" name="Title2" value="Ms" />Ms</label>
        <!-- I WANT ERROR LABEL HERE -->
    </td>
</tr>

Scroll across on the line marked >>> and you'll see the comment that shows there the plugin is putting the error label, just before the closing </td> you'll see where I want the label to go.

Any help appreciated, Thanks.

like image 274
Ben Everard Avatar asked Jul 10 '12 10:07

Ben Everard


People also ask

How to remove error message in jQuery validation?

remove(); $(". error"). removeClass("error"); It will be ok, when you need to validate it again.

How can I show error message below the textbox in jQuery validation?

Java scriptready(function() { $("#basic-form"). validate(); }); This is based on the assumption that you have already added the required JavaScript files. Adding those lines of JavaScript will make sure that your form is properly validated and shows all the error messages.

What is Errorplacement?

Definition of jQuery validate errorplacement. The jQuery validate errorplacement() function is used to customize the placement of an error message. This function is a built-in function in jQuery. These function changes the default behavior of the validation plugin to insert the error label after the input fields.

What is validator in jQuery?

Form validation is a process of confirming the relevant information entered by the user in the input field. Here we will be validating a simple form that consists of a username, password and a confirmed password using jQuery.


1 Answers

Try adding the label tag where you want:

<label class="error" for="Title2" generated="true"></label>

The plugin will use this tag to display error

like image 125
Karan Punamiya Avatar answered Oct 11 '22 21:10

Karan Punamiya