我正在使用client_side_validations gem在rails 3中执行表单验证.
一切正常,除非当firefox/ie抛出javascript警告时,唯一验证ajax运行并返回404错误消息.
作者说404意味着没有找到记录,因此是唯一的;
有什么方法可以解决这个问题.
我打开了这个:https://github.com/bcardarella/client_side_validations/issues/297
EDIT
联系了play-js-validation的作者.出血边缘的东西; Play必须针对要发布的2.10上的scala进行编译,并且尚不支持嵌套的case类.非常令人印象深刻的项目,我希望它能够实现,因为原型几乎完全符合我的希望......
发现这个:https: //github.com/namin/play-js-validation
有人知道Play 2.0中是否有内置客户端验证的计划?
我目前正在基于现有的数据库架构生成控制器,模型(带有表单验证)和dao scala文件; 我希望将客户端验证作为该流程的一部分!
感谢线索,内幕知识等.
ps Play用户组至少可以说是忙碌; 大多数帖子似乎都被完全忽略了(当然,许多Stackoverflow Play相关的问题也没有得到解答,所以这个帖子可能是DOA ...)
scala client-side-validation playframework playframework-2.0
这是我的User模特:
class User < ActiveRecord::Base
rolify
devise :database_authenticatable, :registerable, :token_authenticatable, :confirmable, :timeoutable,
:recoverable, :rememberable, :trackable, :validatable,
:email_regexp => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :confirmed_at, :confirmation_token
validates_uniqueness_of :email, :case_sensitive => false
validates_confirmation_of :password
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile:
gem 'client_side_validations'
形成:
<%= form_for(resource, :as => resource_name, :class => "send-with-ajax", :url => user_registration_path(resource), :validate => true, :html => { :id => 'user_new' }) do |f| %>
<%= f.text_field :email,:placeholder => "your-email@address.com", :input_html => {:autofocus => true}, :validate => true %>
<%= …Run Code Online (Sandbox Code Playgroud) 如果我使用ajax请求获取simple_form,则客户端验证gem不起作用..
<%= link_to 'Add +', new_group_path, :remote => true, :id => "new_group_link" %>
Run Code Online (Sandbox Code Playgroud)
现在,表单新组将显示,并且不会触发客户端验证.
我遇到的问题是客户端功能没有与表单绑定.(javascript资源中指定的函数.)
但是我如何触发这些功能.
编辑
想想标准的脚手架形式.所以按照上面指定的link_to标签.new_group_path将执行新操作并使用respond_to块,将呈现new.js.erb文件.对.这是new.js.erb中的代码
$('#new_group_link').hide().after('<%= j render("form") %>');
Run Code Online (Sandbox Code Playgroud) ajax jquery client-side-validation ruby-on-rails-3 simple-form
我是使用数据注释的asp.net 4.5 webforms模型绑定的忠实粉丝.
ASCX:
<asp:FormView ItemType="Contact" runat="server" DefaultMode="Edit"
SelectMethod="GetContact" UpdateMethod="SaveContact">
<EditItemTemplate>
<asp:ValidationSummary runat="server" ID="valSum" />
Firstname: <asp:TextBox runat="server" ID="txtFirstname" Text='<%#: BindItem.Firstname %>' />
Lastname: <asp:TextBox runat="server" ID="txtLastname" Text='<%#: BindItem.Lastname %>' />
Email: <asp:TextBox runat="server" ID="txtEmail" Text='<%#: BindItem.Email %>' />
<asp:Button ID="Button1" runat="server" Text="Save" CommandName="Update" />
</EditItemTemplate>
</asp:FormView>
Run Code Online (Sandbox Code Playgroud)
的.cs:
public void SaveContact(Contact viewModel)
{
if (!Page.ModelState.IsValid)
{
return;
}
}
public Contact GetContact()
{
return new Contact();
}
Run Code Online (Sandbox Code Playgroud)
模型:
public class Contact
{
[Required]
[StringLength(10, ErrorMessage="{1} tis te lang")]
public string …Run Code Online (Sandbox Code Playgroud) asp.net webforms model-binding client-side-validation data-annotations
我想知道RequiredIfMVC 5中是否存在注释,因为我在尝试使用它时遇到了麻烦,因为它似乎在MVC 5中不存在.有没有解决方案,或者我错过了一些库?(我知道它存在于MVC3中).
在MVC 5中还有任何替代条件验证吗?
提前致谢.
是否可以对用于Class范围的自定义ValidationAttribute进行客户端验证?例如我的MaxLengthGlobal,它应确保所有输入字段的全局最大限制。
[AttributeUsage(AttributeTargets.Class)]
public class MaxLengthGlobalAttribute : ValidationAttribute, IClientValidatable
{
public int MaximumLength
{
get;
private set;
}
public MaxLengthGlobalAttribute(int maximumLength)
{
this.MaximumLength = maximumLength;
}
public override bool IsValid(object value)
{
var properties = TypeDescriptor.GetProperties(value);
foreach (PropertyDescriptor property in properties)
{
var stringValue = property.GetValue(value) as string;
if (stringValue != null && (stringValue.Length > this.MaximumLength))
{
return false;
}
}
return true;
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{
ErrorMessage = this.FormatErrorMessage(metadata.GetDisplayName()),
ValidationType …Run Code Online (Sandbox Code Playgroud) c# model-view-controller class client-side-validation attributeusage
我有一个表单,我根据div点击提交.我点击它时也会启动一个等待指示器.我试图找出是否有办法检测客户端验证是否失败,以便我可以删除等待指示符/从未在提交尝试后显示它...或者我可以手动调用客户端验证在我尝试提交之前?
根据各种来源设置验证后,我无法启动客户端验证方法。经过一番努力,我发现更改脚本加载的顺序可以解决问题。我提供了一个答案来显示 ASP.NET Core 3.0 MVC 的“RequiredIf”自定义属性的完整设置。希望它能节省其他人的宝贵时间。
validation client-side-validation custom-attribute unobtrusive-validation asp.net-core-3.0
请先完整阅读我的问题,然后再将我的问题分配为重复项。 您好,我尝试在按键期间动态验证密码。实际上,输入密码时它对我有用。但是当我删除密码时只满足两个条件。我的代码和图片如下:
我的密码框html代码是
<div class="form-group has-feedback">
<input class="form-control" id="NewPassword" placeholder="New Password" onkeypress="EnterPassword()" onkeydown="DeletePassword()" type="password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
我在密码的每个条件前面使用了 glyphicon-remove 。当我输入密码时,如果满足条件,每个图标都会更改为 glyphicon-ok。
假设我的密码为Password@123,它包含我需要的所有内容,因此所有图标都更改为ok。
函数代码如下:
<script type="text/javascript" >
function EnterPassword() {
$("#NewPassword").keyup(function () {
var regex1 = new Array();
var regex2 = new Array();
var regex3 = new Array();
var regex4 = new Array();
regex1.push("[A-Z]"); //Uppercase Alphabet.
regex2.push("[a-z]"); //Lowercase Alphabet.
regex3.push("[0-9]"); //Digit.
regex4.push("[!@@#$%^&*]"); //Special Character.
if ($(this).val().length>6) {
$("#Length").removeClass("glyphicon glyphicon-remove").addClass("glyphicon glyphicon-ok");
}
for (var i = 0; i …Run Code Online (Sandbox Code Playgroud) jquery ×3
asp.net ×2
c# ×2
validation ×2
ajax ×1
class ×1
client-side ×1
devise ×1
heroku ×1
html ×1
javascript ×1
scala ×1
simple-form ×1
webforms ×1