简体   繁体   English

Bassistance验证无法与jqTransform一起正常使用

[英]Bassistance Validation not working correctly with jqTransform

I'm using jqTransform to style my forms which works very well. 我正在使用jqTransform设置样式,效果很好。 However, when I add Bassistance's Validation plugin, the validation error messages are shown within the jqTransformwrapper divs (ie inside the textbox) instead of the parent element (after input). 但是,当我添加Bassistance的Validation插件时,验证错误消息显示在jqTransformwrapper div中(即在文本框内),而不是父元素(输入后)。

So the DOM shows this: 因此,DOM显示如下:

<label for="firstname">Firstname</label>
<div class="jqTransformInputWrapper">
   <div class="jqTransformInputInner">
      <div><input class="required jqtranformdone jqTransformInput error" name="firstname" id="firstname">
      <label for="firstname" generated="true" class="error">This field is required.</label>
      </div>
   </div>

Whereas it should be: 而应该是:

<label for="firstname">Firstname</label>
<div class="jqTransformInputWrapper">
   <div class="jqTransformInputInner">
      <div>
         <input class="required jqtranformdone jqTransformInput error" name="firstname" id="firstname">
      </div>
   </div>
</div>
<label for="firstname" generated="true" class="error">This field is required.</label>
</div>

Is there any way I can get the plugin to insert the error label 3 parent's higher? 有什么办法可以让我的插件插入错误标签3父母的更高?

I notice on Bassistance's example page they use a different form styling plugin and dont have this problem, but I cant figure out how they did it. 我在Bassistance的示例页面上注意到他们使用了不同的表单样式插件,并且没有此问题,但是我无法弄清楚他们是如何做到的。 http://jquery.bassistance.de/validate/demo/themerollered.html http://jquery.bassistance.de/validate/demo/themerollered.html

Look for this in your call to the validate function: 在对validate函数的调用中查找以下内容:

errorPlacement: function(error, element) {
                    if ( element.is(":text") )
                        error.appendTo( element.parent().parent().parent().parent() );
                    else
                        error.appendTo( element.parent().next() );
                }

notice the .parent() sequence. 注意.parent()序列。 you can target different areas like this. 您可以像这样定位不同的区域。 its called the jquery selector. 它称为jquery选择器。 other options incl: .children() .next() .prev() 其他选项包括:.children().next().prev()

Please note that I have specified text input as the origin. 请注意,我已将文本输入指定为原点。 by using this many parent() selectors, you are able to escape the jqtransform wrapping divs and reach the outside world. 通过使用这么多的parent()选择器,您可以逃脱jqtransform包装div并到达外界。

play with combinations to place the label exactly where you want! 玩组合,将标签准确放置在您想要的位置!

As a workaround I set the row div to relative positioning and the error message to absolute so that it is relative to the div. 作为一种解决方法,我将行div设置为相对位置,并将错误消息设置为绝对值,以使其相对于div。

#myForm label.error {
   color:#dd0000;
   position:absolute;
   float:none;
   font-style:italic;
   left:350px;
   top:4px;
}

This way the error appears alongside each input instead of inside it :) 这样,错误出现在每个输入旁边,而不是在里面:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM