简体   繁体   English

使用角度js验证问题(firefox上的红色边框显示)?

[英]validation issue using angular js (red border display on firefox)?

I make a simple form from object ..now i validate that form .I am facing few issues while validation.please check this on firefox.. 我从对象创建一个简单的表单..现在我验证该表单.validation时遇到几个问题。请在Firefox上进行检查。

http://plnkr.co/edit/CFUR2mgVv4hzXPF7AR9y?p=preview http://plnkr.co/edit/CFUR2mgVv4hzXPF7AR9y?p=preview

  • My field become red (red border on input field)when i write required true and display message "please enter the valid email" after run app.it should become red when user move focus one field to another.and i need to display two message "please enter the email" with "please enter the valid email" how I can do that ? 我的字段变成红色(输入字段上的红色边框),当我写了必填内容,并在运行应用程序后显示消息“请输入有效的电子邮件”。当用户将焦点移到另一个字段时,它应该变成红色。我需要显示两个消息如何输入“请输入电子邮件”和“请输入有效的电子邮件”?

I study lot of tutorial but I apply this thing $dirty , $pristine but nothing works for me.. I study from there validation .. http://scotch.io/tutorials/javascript/angularjs-form-validation 我研究了很多教程,但是我应用了$ dirty,$ pristine这个东西但是对我没有用。.我从那里学习验证.. http://scotch.io/tutorials/javascript/angularjs-form-validation

<ul ng-repeat="input in inputs">
        <li><span>{{input.name}} : </span>

            <div ng-switch="input.type" ng-form="myfrm">
                <div ng-switch-when="text">
                    <input type="text" ng-model="outputs[input.name]"/>
                </div>
                <div ng-switch-when="email" class="form-group" >
                    <input type="email" ng-model="outputs[input.name]" name="input" ng-required="input.required">
                    <P ng-show="myfrm.input.$invalid  && !myform.input.$pristine">Please enter a valid email</P>


                </div>
                <div ng-switch-when="number">
                    <input type="number" ng-model="outputs[input.name]"  ng-required="input.required" name="input"/>
                     <P ng-if="myfrm.input.$invalid">Please enter a valid number</P>
                </div>
                <div ng-switch-when="url">
                    <input type="number" ng-model="outputs[input.name]"/>
                </div>
                <div ng-switch-when="checkbox">
                    <input type="checkbox" ng-model="outputs[input.name]" ng-checked="outputs[input.name]" value="outputs[input.name]"/>
                </div>
            </div>
        </li>
    </ul>

There is a typo where you use $pristine , the myform should be myfrm like you set in ng-form : 在使用$pristine有一个错字,就像在ng-form设置的那样, myform应该是myfrm

<p ng-show="myfrm.input.$invalid && !myfrm.input.$pristine">Please enter a valid email</p>

To show different messages for invalid email and empty email, you could use $error instead of $invalid like this: 要为无效电子邮件和空电子邮件显示不同的消息,可以使用$error代替$invalid如下所示:

<p ng-show="myfrm.input.$error.email && !myfrm.input.$pristine">Please enter a valid email</p>
<p ng-show="myfrm.input.$error.required && !myfrm.input.$pristine">Please enter the email</p>

Example Plunker: http://plnkr.co/edit/eD4OZ8nqETBACpSMQ7Tm?p=preview Plunker示例: http ://plnkr.co/edit/eD4OZ8nqETBACpSMQ7Tm?p=preview

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

相关问题 Firefox 问题:焦点更改时输入文本元素周围的红色边框 - Firefox Issue: Red border around Input text element on focus change 如何在Angular JS中的按钮的输入字段中显示红色边框 - how to show red border in input field on button In angular js 如果日期在Angular JS中无效,如何使边框变为红色? - how to make border red if date is invalid in angular js? JS表单验证:在带有错误的输入字段上添加红色边框; 重点消除? - JS Form Validation: adding a red border on input fields with errors; removing it on focus? jQuery 验证红色边框没有立即显示 - jQuery validation red border not showing immediately Validation in JavaScript - 如何让红色边框消失? - Validation in JavaScript - how to make the red border disappear? 使用该特定字段周围的红色边框对空字符串进行表单验证检查 - Form validation check for empty string using red border around that particular field 使用checkValidity的HTML 5表单验证不显示默认的红色/橙色边框 - HTML 5 form validation using checkValidity doesn't show default red/orange border 尝试使用Angular.js显示验证消息时出现错误 - Getting error while trying to display validation message using Angular.js Angular JS XML数据显示问题 - Angular JS XML data display issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM