Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://docs.jquery.com/Plugins/Validation/validate#toptions" rel="nofollow noreferrer">errorPlacement</a> option to override the error message display with little css. Because css on its own will not be enough to produce the effect you need.</p> <pre><code>$(document).ready(function(){ $("#myForm").validate({ rules: { "elem.1": { required: true, digits: true }, "elem.2": { required: true } }, errorElement: "div", wrapper: "div", // a wrapper around the error message errorPlacement: function(error, element) { offset = element.offset(); error.insertBefore(element) error.addClass('message'); // add a class to the wrapper error.css('position', 'absolute'); error.css('left', offset.left + element.outerWidth()); error.css('top', offset.top); } }); }); </code></pre> <p>You can play with the left and top css attributes to show the error message on top, left, right or bottom of the element. For example to show the error on the top:</p> <pre><code> errorPlacement: function(error, element) { element.before(error); offset = element.offset(); error.css('left', offset.left); error.css('top', offset.top - element.outerHeight()); } </code></pre> <p>And so on. You can refer to <a href="http://docs.jquery.com/CSS" rel="nofollow noreferrer">jQuery documentation about css</a> for more options.</p> <p>Here is the css I used. The result looks exactly like the one you want. With as little CSS as possible:</p> <pre><code>div.message{ background: transparent url(msg_arrow.gif) no-repeat scroll left center; padding-left: 7px; } div.error{ background-color:#F3E6E6; border-color: #924949; border-style: solid solid solid none; border-width: 2px; padding: 5px; } </code></pre> <p>And here is the background image you need:</p> <p><a href="http://sandbox.scriptiny.com/messages/images/msg_arrow.gif" rel="nofollow noreferrer">alt text http://sandbox.scriptiny.com/messages/images/msg_arrow.gif</a></p> <p>If you want the error message to be displayed after a group of options or fields. Then group all those elements inside one container a 'div' or a 'fieldset'. Add a special class to all of them 'group' for example. And add the following to the begining of the errorPlacement function:</p> <pre><code>errorPlacement: function(error, element) { if (element.hasClass('group')){ element = element.parent(); } ...// continue as previously explained </code></pre> <p>If you only want to handle specific cases you can use attr instead:</p> <pre><code>if (element.attr('type') == 'radio'){ element = element.parent(); } </code></pre> <p>That should be enough for the error message to be displayed next to the parent element.</p> <p>You may need to change the width of the parent element to be less than 100%.</p> <hr> <p>I've tried your code and it is working perfectly fine for me. Here is a preview: <img src="https://s12.postimg.cc/6z1jnovz1/gt5o0.png" alt="alt text"></p> <p>I just made a very small adjustment to the message padding to make it fit in the line:</p> <pre><code>div.error { padding: 2px 5px; } </code></pre> <p>You can change those numbers to increase/decrease the padding on top/bottom or left/right. You can also add a height and width to the error message. If you are still having issues, try to replace the span with a div </p> <pre><code>&lt;div class="group"&gt; &lt;input type="radio" class="checkbox" value="P" id="radio_P" name="radio_group_name"/&gt; &lt;label for="radio_P"&gt;P&lt;/label&gt; &lt;input type="radio" class="checkbox" value="S" id="radio_S" name="radio_group_name"/&gt; &lt;label for="radio_S"&gt;S&lt;/label&gt; &lt;/div&gt; </code></pre> <p>And then give the container a width (this is very important)</p> <pre><code>div.group { width: 50px; /* or any other value */ } </code></pre> <p>About the blank page. As I said I tried your code and it is working for me. It might be something else in your code that is causing the issue.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload