Javascript 表单完成时Form.io页面重定向
我越来越熟悉和学习angularjs,因为我们开始使用form.io将创建的表单直接嵌入到带有模块的网页中 我已经介绍了多个关于模块和事件触发的示例,以及基于$emit和$broadcast触发哪个方向的事件。但实际上,我正试图捕获由formio模块触发的事件 通过简单地将代码放在下面,在主体中使用Angular并显示表单就足够容易了Javascript 表单完成时Form.io页面重定向,javascript,angularjs,forms,Javascript,Angularjs,Forms,我越来越熟悉和学习angularjs,因为我们开始使用form.io将创建的表单直接嵌入到带有模块的网页中 我已经介绍了多个关于模块和事件触发的示例,以及基于$emit和$broadcast触发哪个方向的事件。但实际上,我正试图捕获由formio模块触发的事件 通过简单地将代码放在下面,在主体中使用Angular并显示表单就足够容易了 <formio src="'https://ofnatmqalooynpz.form.io/testform'"></formio> &l
<formio src="'https://ofnatmqalooynpz.form.io/testform'"></formio>
<script type="text/javascript">
angular.module('formioApp', ['formio']);
angular.bootstrap(document, ['formioApp']);
</script>
但是每当我尝试创建一个控制器时,表单都不会加载或无法工作。我肯定理解这是我在角度上缺乏理解
<script type="text/javascript">
var formioApp = angular.module('formioApp', ['formio']);
angular.bootstrap(document, ['formioApp']);
formioApp.controller('formio',['$scope','$controller','$rootScope', function($scope,$controller,$rootScope) {
$scope.$on('formSubmission', function(err, submission) { /* page redirect*/ });
});
</script>
var formioApp=angular.module('formioApp',['formio']);
引导(文档,['formioApp']);
formioApp.controller('formio',['$scope','$controller','$rootScope',函数($scope,$controller,$rootScope){
$scope.$on('formSubmission',函数(err,submission){/*页面重定向*/});
});
我认为从模块中捕获事件应该非常简单,所以我肯定错过了一些非常简单的东西。示例
Example
You can easily render a form within your Angular 2 application by referencing the URL of that form as follows.
<formio src='https://examples.form.io/example'></formio>
You can also pass the JSON form directly to the renderer as follows.
<formio [form]="{
title: 'My Test Form',
components: [
{
"type": "textfield",
"input": true,
"tableView": true,
"inputType": "text",
"inputMask": "",
"label": "First Name",
"key": "firstName",
"placeholder": "Enter your first name",
"prefix": "",
"suffix": "",
"multiple": false,
"defaultValue": "",
"protected": false,
"unique": false,
"persistent": true,
"validate": {
"required": true,
"minLength": 2,
"maxLength": 10,
"pattern": "",
"custom": "",
"customPrivate": false
},
"conditional": {
"show": "",
"when": null,
"eq": ""
}
},
{
"type": "textfield",
"input": true,
"tableView": true,
"inputType": "text",
"inputMask": "",
"label": "Last Name",
"key": "lastName",
"placeholder": "Enter your last name",
"prefix": "",
"suffix": "",
"multiple": false,
"defaultValue": "",
"protected": false,
"unique": false,
"persistent": true,
"validate": {
"required": true,
"minLength": 2,
"maxLength": 10,
"pattern": "",
"custom": "",
"customPrivate": false
},
"conditional": {
"show": "",
"when": null,
"eq": ""
}
},
{
"input": true,
"label": "Submit",
"tableView": false,
"key": "submit",
"size": "md",
"leftIcon": "",
"rightIcon": "",
"block": false,
"action": "submit",
"disableOnInvalid": true,
"theme": "primary",
"type": "button"
}
]
}"></formio>
通过引用Angular 2应用程序中的表单URL,可以轻松地在该表单中呈现表单,如下所示。
您还可以将JSON表单直接传递给呈现器,如下所示。
我最终自己发现了这一点。由于我对angular及其工作方式缺乏经验,这需要花费更多的时间和精力。此外,我的答案很可能(我知道)不是angular的最佳实践以及form.io应该如何工作,但它完全满足了我的需要
var formioApp = angular.module('formioApp', ['formio']);
formioApp.controller('formio', ['$scope','$controller','$rootScope', function($scope,$controller,$rootScope) {
console.log('here I am');
$scope.resetForm = () => { console.debug('yes'); }
$scope.$on('formSubmission', function(e, submission) {
//e.preventDefault(); --stops submission to server
e.stopPropagation();
console.log('submitted');
window.location.replace("/contact_thanks.html");
});
}]);
我的body标签如下所示:
如果我只是试图在页面上呈现表单,这很简单。我试图捕获模块触发的事件,以便在表单完成后执行页面重定向。这是他们文档中描述的方法。
var formioApp = angular.module('formioApp', ['formio']);
formioApp.controller('formio', ['$scope','$controller','$rootScope', function($scope,$controller,$rootScope) {
console.log('here I am');
$scope.resetForm = () => { console.debug('yes'); }
$scope.$on('formSubmission', function(e, submission) {
//e.preventDefault(); --stops submission to server
e.stopPropagation();
console.log('submitted');
window.location.replace("/contact_thanks.html");
});
}]);