如何显示不同的信息所需的和无效的? [英] how to show different message on required and invalid?

查看:158
本文介绍了如何显示不同的信息所需的和无效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以请你告诉我如何显示所需的和无效的?换句话说不同的消息。使使用的插件。在有一些必需的参数。而一些我需要验证例如电子邮件。当JSON形式用户preSS提交按钮,如果用户不填写它显示,如果用户填写的价值,但不一样的彭定康比它说:这个字段是必须的。而场无效值。可我们展示不同的消息不同的局面。

我用这个插件
https://github.com/Textalk/angular-schema-form/blob/master/docs/index.md#validation-messages
我使这个plunker
http://plnkr.co/edit/ZNJO3x3IqajjdMNStJMF?p=$p$pview

  angular.module('测试',['schemaForm'])。控制器('的FormController',函数($范围,$ HTTP){
   $ scope.schema = {
    类型:对象
    属性:{
      名称:{类型:串的minLength:2,标题:姓名,说明:名称或别名,必需:true,默认:DDDD},
      学生:{类型:字符串,标题:studentname介绍:姓名或学生,必需:false},      电子邮件:{
      头衔:电子邮件,
      类型:串,
       模式:\\ w +([ - +'。] \\ w +)* @ \\ w +( - \\ w +。])* \\ \\ w +( - \\ w +。])*。      说明:电子邮件将被用于作恶。
      要求:真
    },
      标题:{
        类型:串,
        要求:真实,
        枚举:['博士','JR','先生','夫人','先生','NaN的','DJ'],      }
    }
  };  $ scope.form = [
    *,
    {
      键入:提交,
      标题:保存
    }
  ];


正如您可能从的官方角架构形式的文档


  

每默认情况下所有的错误消息来自架构验证TV4 ,这可能会或可能不会为你工作。如果你在表单定义提供一个validationMessage属性,如果它的值是一个将被使用在任何验证错误的字符串。


  
  

如果您需要更细粒度的控制,你可以改为匹配错误$ C $ TV4的CS键提供的对象。见tv4.error codeS


  
  

  {
  键:address.street
  validationMessage:{
    tv4.error codes.STRING_LENGTH_SHORT:地址是太短了,人,
    默认:就写一个正确的地址,你愿意吗? //特别包罗万象的错误信息
  }
}

您还可以设置在formDefaults一个全球性的validationMessage看到全局选项。


因此​​,对于更多的错误信息,请访问此链接

can you please tell me how to show different message on required and invalid ?In other word .make a form from json using plugin .In that there are some required parameter .and some I need to validate example "Email".When user press "submit" button if user did not fill the field it show "this field is required" .and if user fill the value but not same patten than it say "invalid value".can we show different message as different situation .

i used this plugin https://github.com/Textalk/angular-schema-form/blob/master/docs/index.md#validation-messages and I make this plunker http://plnkr.co/edit/ZNJO3x3IqajjdMNStJMF?p=preview

angular.module('test',['schemaForm']).controller('FormController', function($scope,$http){
   $scope.schema = {
    type: "object",
    properties: {
      name: { type: "string", minLength: 2, title: "Name", description: "Name or alias" ,required:true,"default": "dddd"},
      "student": { type: "string", title: "studentname", description: "Name or student" ,required:false},

      "email": {
      "title": "Email",
      "type": "string",
       "pattern":"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*",

      "description": "Email will be used for evil.",
      required:true
    },
      title: {
        type: "string",
        required:true,
        enum: ['dr','jr','sir','mrs','mr','NaN','dj'],

      }
    }
  };

  $scope.form = [
    "*",
    {
      type: "submit",
      title: "Save"
    }
  ];

解决方案

As you may read from the official angular-schema-form documentation

Per default all error messages comes from the schema validator tv4, this might or might not work for you. If you supply a validationMessage property in the form definition, and if its value is a string that will be used instead on any validation error.

If you need more fine grained control you can supply an object instead with keys matching the error codes of tv4. See tv4.errorCodes

Ex.

{
  key: "address.street",
  validationMessage: {
    tv4.errorCodes.STRING_LENGTH_SHORT: "Address is too short, man.",
    "default": "Just write a proper address, will you?"   //Special catch all error message
  }
}

You can also set a global validationMessage in formDefaults see Global Options.

So for more error messages, visit this link

这篇关于如何显示不同的信息所需的和无效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆