admin管理员组文章数量:1279090
I am trying to get a very simple angular validation form using the angular material framework. I am building this form in a Sharepoint 2010 content editor webpart which dosent allow the use of . Im working on rebuilding the form instead on a webpage but not getting into other more plex issues.
But I dive into other issues im just wondering if a angular validation form can work without the element? Or if theres other directives that could replace it?
Heres a small example of what im aiming for but without the form element.
/?utm_source=website&utm_medium=embed&utm_campaign=yfLqfzLw
<div class="container" id="demoApp">
<form class="pure-form pure-form-aligned" name="frm" method="post"
novalidate autoplete="off">
<fieldset>
<div class="pure-control-group">
<label>Username</label>
<input name="username" ng-model="user.username" type="text" placeholder="Username" required>
<div class="field-message" ng-messages="frm.username.$error" ng-if='frm.username.$dirty' ng-cloak>
<div ng-message="required">Username is required</div>
</div>
</div>
<div class="pure-control-group">
<label>Password</label>
<input name="password"
ng-model="user.password"
type="password"
placeholder="Password"
required
ng-minlength="6"
ng-maxlength="10">
<div class="field-message" ng-messages="frm.password.$error" ng-if='frm.password.$dirty' ng-cloak>
<div ng-message="required">Password is required</div>
<div ng-message="minlength">Password must have minimum 6 characters</div>
<div ng-message="maxlength">Password must have maximum 10 characters</div>
</div>
</div>
<div class="pure-control-group">
<label>Email Address</label>
<input name="email"
ng-model="user.email"
type="email"
placeholder="Email Address"
required>
<div class="field-message" ng-messages="frm.email.$error" ng-if='frm.email.$dirty' ng-cloak>
<div ng-message="required">Email is required</div>
<div ng-message="email">Must be a valid email</div>
</div>
</div>
<div class="pure-controls">
<label class="pure-checkbox">
<input name="conditions" ng-model="conditions" type="checkbox">
I've read the terms and conditions
</label>
<button type="submit" class="pure-button pure-button-primary"
ng-disabled="frm.$invalid || !conditions">Submit</button>
</div>
</fieldset>
</form>
</div>
Anyone have any information on this? Having no luck finding documentation on this.
I am trying to get a very simple angular validation form using the angular material framework. I am building this form in a Sharepoint 2010 content editor webpart which dosent allow the use of . Im working on rebuilding the form instead on a webpage but not getting into other more plex issues.
But I dive into other issues im just wondering if a angular validation form can work without the element? Or if theres other directives that could replace it?
Heres a small example of what im aiming for but without the form element.
http://jsfiddle/jhadesdev/yfLqfzLw/2/?utm_source=website&utm_medium=embed&utm_campaign=yfLqfzLw
<div class="container" id="demoApp">
<form class="pure-form pure-form-aligned" name="frm" method="post"
novalidate autoplete="off">
<fieldset>
<div class="pure-control-group">
<label>Username</label>
<input name="username" ng-model="user.username" type="text" placeholder="Username" required>
<div class="field-message" ng-messages="frm.username.$error" ng-if='frm.username.$dirty' ng-cloak>
<div ng-message="required">Username is required</div>
</div>
</div>
<div class="pure-control-group">
<label>Password</label>
<input name="password"
ng-model="user.password"
type="password"
placeholder="Password"
required
ng-minlength="6"
ng-maxlength="10">
<div class="field-message" ng-messages="frm.password.$error" ng-if='frm.password.$dirty' ng-cloak>
<div ng-message="required">Password is required</div>
<div ng-message="minlength">Password must have minimum 6 characters</div>
<div ng-message="maxlength">Password must have maximum 10 characters</div>
</div>
</div>
<div class="pure-control-group">
<label>Email Address</label>
<input name="email"
ng-model="user.email"
type="email"
placeholder="Email Address"
required>
<div class="field-message" ng-messages="frm.email.$error" ng-if='frm.email.$dirty' ng-cloak>
<div ng-message="required">Email is required</div>
<div ng-message="email">Must be a valid email</div>
</div>
</div>
<div class="pure-controls">
<label class="pure-checkbox">
<input name="conditions" ng-model="conditions" type="checkbox">
I've read the terms and conditions
</label>
<button type="submit" class="pure-button pure-button-primary"
ng-disabled="frm.$invalid || !conditions">Submit</button>
</div>
</fieldset>
</form>
</div>
Anyone have any information on this? Having no luck finding documentation on this.
Share Improve this question asked Nov 29, 2016 at 0:25 Daniel EllisonDaniel Ellison 1,3474 gold badges27 silver badges52 bronze badges1 Answer
Reset to default 12The AngularJs ngForm direcive doesn't require the element to be a <form>
, you can use the ng-form
in a div
if you like. For example, taken from your fiddle you have this div
replacing the previous form
element.
<div ng-form="frm" class="pure-form pure-form-aligned">
...
</div>
Full working snippet:
angular.module('DemoApp', ['ngMessages']);
angular.bootstrap(document.getElementById('demoApp'), ['DemoApp']);
@import "http://yui.yahooapis./pure/0.6.0/pure-min.css";
.container {
width: 970px;
padding-top: 10px;
margin: 0 auto;
}
.pure-form input.ng-dirty.ng-invalid {
border-color: #e9322d;
}
.field-message {
display: inline-block;
color: #e9322d;
font-size: 90%;
margin-left: 0.5em;
}
[ng\:cloak],
[ng-cloak],
[data-ng-cloak],
[x-ng-cloak],
.ng-cloak,
.x-ng-cloak {
display: none !important;
}
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.3.14/angular.js"></script>
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.3.14/angular-messages.js"></script>
<div class="container" id="demoApp">
<div ng-form="frm" class="pure-form pure-form-aligned" autoplete="off">
<fieldset>
<div class="pure-control-group">
<label>Username</label>
<input name="username" ng-model="user.username" type="text" placeholder="Username" required>
<div class="field-message" ng-messages="frm.username.$error" ng-if='frm.username.$dirty' ng-cloak>
<div ng-message="required">Username is required</div>
</div>
</div>
<div class="pure-control-group">
<label>Password</label>
<input name="password" ng-model="user.password" type="password" placeholder="Password" required ng-minlength="6" ng-maxlength="10">
<div class="field-message" ng-messages="frm.password.$error" ng-if='frm.password.$dirty' ng-cloak>
<div ng-message="required">Password is required</div>
<div ng-message="minlength">Password must have minimum 6 characters</div>
<div ng-message="maxlength">Password must have maximum 10 characters</div>
</div>
</div>
<div class="pure-control-group">
<label>Email Address</label>
<input name="email" ng-model="user.email" type="email" placeholder="Email Address" required>
<div class="field-message" ng-messages="frm.email.$error" ng-if='frm.email.$dirty' ng-cloak>
<div ng-message="required">Email is required</div>
<div ng-message="email">Must be a valid email</div>
</div>
</div>
<div class="pure-controls">
<label class="pure-checkbox">
<input name="conditions" ng-model="conditions" type="checkbox">I've read the terms and conditions
</label>
<button type="submit" class="pure-button pure-button-primary" ng-disabled="frm.$invalid || !conditions">Submit</button>
</div>
</fieldset>
</div>
</div>
本文标签: javascriptAngular form validation but without ltformgtStack Overflow
版权声明:本文标题:javascript - Angular form validation but without <form>? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741300450a2371060.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论