【问题标题】:grails field plugin: the "blank" error is not handled the same way as others?grails field plugin:“空白”错误的处理方式与其他错误不同吗?
【发布时间】:2013-05-23 10:13:31
【问题描述】:

我正在使用 Grails 的 fields plugin,因为它在编写表单方面很短。

不过,我不太了解它管理验证错误的方式。

如果域类作为“空白”约束,插件会在相应的属性/字段附近显示一个漂亮的箭头弹出消息“请填写此字段”,即使没有写入明确的错误管理代码控制器,甚至是表单。

当我查看messages.properties时,default.blank.message"Property [{0}] of class [{1}] cannot be blank",所以我不明白这个插件给出的消息来自哪里。

此外,如果我尝试另一个约束,例如"minSize:2",则错误不会以“空白”的形式显示,除非我以常规方式处理和显示它(控制器和视图中的代码) .

所以,我的问题是:在外地插件中

  1. 为什么“空白”验证与其他错误不同?
  2. 如何对所有错误重复使用漂亮的错误弹出窗口?
  3. 此弹出窗口的 javascript 代码在哪里?

【问题讨论】:

    标签: validation grails plugins field


    【解决方案1】:

    这个弹出窗口是使用 HTML5 的属性 required 进行客户端验证的结果,它不需要任何 JavaScript -- see examples here

    您使用属性required 的任何html input 字段都会得到该弹出窗口:

    <input type="text" name="fieldName" required />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-16
      • 2013-01-24
      • 2015-09-24
      • 2013-05-16
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 2021-07-18
      相关资源
      最近更新 更多