gpt4 book ai didi

javascript - 如何使用 Angular 形式使用模糊事件?

转载 作者:行者123 更新时间:2023-12-03 12:02:56 26 4
gpt4 key购买 nike

我用这个 link 制作了一个表单

我能够在单击按钮时验证表单,但有方法可以验证 onBlur 但我不明白如何实现这一点。

这是我的 plunker

<!DOCTYPE html>
<html >

<head>

<link data-require="bootstrap-css@3.x" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />


<link rel="stylesheet" href="style.css" />

</head>

<body ng-app="test" ng-controller="FormController">

<form name="ngform"
sf-schema="schema"
sf-form="form"
sf-model="model" sf-options="{ formDefaults: { ngModelOptions: { updateOn: 'blur' } }}" ng-submit="onSubmit(ngform)"></form>

<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//dl.dropboxusercontent.com/s/icrciconaesuw29/tv4.js?m="></script>
<script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="//code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script src="//dl.dropboxusercontent.com/s/unk0id7tmc9w0mm/angular-sanitize.js?m="></script>
<script src="//dl.dropboxusercontent.com/s/rk0dfetihiqs7bi/ObjectPath.js"></script>
<script src="//dl.dropboxusercontent.com/s/8fq4c4t7jct4w4h/schema-form.js?m="></script>
<script type="text/javascript" src="//textalk.github.io/angular-schema-form/dist/bootstrap-decorator.min.js"></script>

<script>
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},
"email": {
"title": "Email",
"type": "string",
"pattern": "^\\S+@\\S+$",
validationMessage: {
"default": "Just write a proper address, will you?" //Special catch all error message
},
"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"
}
];

$scope.model = {};
$scope.onSubmit = function(form) {
// First we broadcast an event so all fields validate themselves
$scope.$broadcast('schemaFormValidate');

// Then we check if the form is valid
if (form.$valid) {
// ... do whatever you need to do with your data.
}
}
})
</script>

</body>

</html>

最佳答案

ngModelOptions 功能已 introduced在 angularjs v1.3.0-beta.6 中

您必须使用 v1.3.0-beta.6 或更高版本,然后您的 plunker 才能正常工作!

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

关于javascript - 如何使用 Angular 形式使用模糊事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325793/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com