IONIC 表单(FORM)验证
2016-09-22 18:31
381 查看
1、创建IONIC 项目 不懂可以点这里
创建项目
2、我们以修改密码为列
我们只需 在外面 嵌套一个 form 如果 controller 需要 额外验证或者其他 你可以给他 命个名 name,如果不需不起也行
Controller
Service 定义 后台请求
如果有空值则界面应该是这样
如果 都不为空界面应该是这样
创建项目
2、我们以修改密码为列
<ion-view title="修改密码"> <ion-nav-bar> <ion-header-bar class="nav-title-slide-ios7 bar-light" align-title="center"> <ion-nav-buttons side="left"> <a class="button button-icon icon ion-ios-undo-outline" style="font-size: 30px;" ng-click="backBtn();"></a> </ion-nav-buttons> </ion-header-bar> </ion-nav-bar> <ion-content> <form name="dataForm" novalidate="novalidate" ng-submit="save(dataForm);"> <div class="list"> <label class="item item-input item-floating-label"> <span class="input-label">原密码</span> <input type="password" ng-model="data.password" required placeholder="请输入原密码"> </label> <label class="item item-input item-floating-label"> <span class="input-label">新密码</span> <input type="password" ng-model="data.newPassword" required placeholder="密码为英文和数字组成"> </label> <label class="item item-input item-floating-label"> <span class="input-label">确认密码</span> <input type="password" ng-model="data.confirmPassword" required placeholder="请确认登录密码"> </label> <label class="item"> <button class="button button-block button-positive" type="submit" ng-disabled="dataForm.$invalid">确认修改</button> </label> </div> </form> </ion-content> </ion-view>
我们只需 在外面 嵌套一个 form 如果 controller 需要 额外验证或者其他 你可以给他 命个名 name,如果不需不起也行
Controller
//========================修改密码=========================== .controller('UpdatePwdCtrl', function($scope, $state, $ionicHistory, LoginService, popupUtil) { $scope.data = {}; $scope.backBtn = function(){ $ionicHistory.goBack(); }; $scope.save = function(dataForm){ if(dataForm.$valid){//成功为 true 否则为 false $scope.changPassword(); } } $scope.changPassword = function (){ if($scope.data.confirmPassword == $scope.data.newPassword){ delete $scope.data.confirmPassword; LoginService.changepassword($scope.data) .$promise.then(function(resp){ if(resp.success){//修改成功 popupUtil.showAlert('提示','密码修改成功'); $state.go('login');//跳转登录页面 }else{ popupUtil.showAlert('提示','密码修改失败'); } }, function(err){ }); }else{ popupUtil.showAlert('提示','两次密码输入不正确'); } }; })Service 定义 popupUtil
//============消息弹框============ .provider('popupUtil', function(){ this.$get = function($ionicPopup){ var popupUtil = {}; popupUtil.showConfirm = function(titleTxt, contentTxt){ var confirmPopup = $ionicPopup.confirm({ title: titleTxt, template: contentTxt }); return confirmPopup; }; popupUtil.showAlert = function(titleTxt, contentTxt) { var alert = $ionicPopup.alert({ title: titleTxt, template: contentTxt }); return alert; }; return popupUtil; } })
Service 定义 后台请求
.factory('LoginService', function($resource){ return $resource('', {}, { 'login' : {//登录 url : 'sec/login', method : 'POST', isArray : false }, 'logout' : {//退出 url : 'sec/logout', method : 'GET', isArray : false }, 'changepassword' : {//修改密码 url : 'sec/changepassword', method : 'POST', isArray : false } }); })此次验证不能为空
如果有空值则界面应该是这样
如果 都不为空界面应该是这样
相关文章推荐
- Form表单验证
- Form表单提交、自定义验证规则(validate插件)
- 简易的JS验证FORM表单特殊字符,防范SQL语句漏洞
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
- form表单验证
- Form表单验证
- yii2 modal弹窗之ActiveForm ajax表单异步验证
- jQuery formValidator表单验证插件3.5a 版本发布,适合jQuery1.3.2类库
- yii2关闭form表单的实时验证
- 基于BootstrapValidator的Form表单验证(24)
- a链接易混淆与form表单简易验证用法详解
- Struts 1.x 表单的Form验证
- Django-Form表单(验证、定制、错误信息、Select)
- 轻量级实用JQuery表单验证插件:validateForm5
- Form表单验证控件分享
- Ionic ngMessage 表单验证
- Spring中试用SimpleFormController 完成表单验证
- ExtJs 备忘录(3)—— Form表单(三) [ 数据验证 ]
- jQuery formValidator表单验证插件开源了 含API帮助、源码、示例
- PHP jQuery Ajax提交与验证form表单详解