I am making a form from json .i am using angular-schema-form with dependancy in tv4.js.I study from this https://github.com/Textalk/angular-schema-form/blob/master/docs/index.md#global-options That we can apply onchange went on element .but when I apply it not call it also not giving any error why ? Plunker http://plnkr.co/edit/wbziK5aRUg69JuwXDoVy?p=preview
我正在从json制作一个表单。我在tv4.js.中使用angular-schema-form和依赖。我从这里学习https://github.com/Textalk/angular-schema-form/blob/master/docs/index .md #global-options我们可以应用onchange继续元素。但是当我应用它时不调用它也没有给出任何错误原因? Plunker http://plnkr.co/edit/wbziK5aRUg69JuwXDoVy?p=preview
onChange: function(modelValue,form) {
console.log("Password is",modelValue);
}
I used like that
我这样用过
"email": {
"title": "Email",
"type": "string",
"minLength": 2,
"pattern": "^\\S+@\\S+$",
onChange: function(modelValue,form) {
console.log("Password is"+modelValue);
},
validationMessage: {
200: "Address is too short, man.",
"default": "Just write a proper address, will you?" //Special catch all error message
},
"description": "Email will be used for evil.",
required: true
},
is there problem in binding ?
绑定有问题吗?
2 个解决方案
#1
1
You added onChange in a wrong place. it should be not in schema but in form. check this one http://plnkr.co/edit/h02XKqF3Vc6eefTOEN8m?p=preview
你在错误的地方添加了onChange。它应该不是在架构中而是在形式上。检查这个http://plnkr.co/edit/h02XKqF3Vc6eefTOEN8m?p=preview
$scope.form = [
"name",
"student",
{
key: "email",
onChange: function(modelValue, form) {
console.log("email changed");
console.debug(modelValue);
console.debug(form);
}
},
"title",
{
type: "submit",
title: "Save"
}
];
Though for email field event is not triggered until you enter valid value. not sure if it should work like that.
虽然在输入有效值之前不会触发电子邮件字段事件。不确定它是否应该像那样工作。
You're also missing angular-schema-form tag because this question is related to that particular library.
您还缺少angular-schema-form标记,因为此问题与该特定库有关。
BR
#2
1
I had a look on the sfChanged directive. Unfortunately...
我看了一下sfChanged指令。不幸...
I didn't want to spend a lot of time to just bind a change event. Maybe this tool is not serious...
我不想花很多时间来绑定更改事件。也许这个工具不严肃......
To plug the change event logic, on your html form object ensure that:
要插入更改事件逻辑,请在html表单对象上确保:
ng-model (add to sf-model, sf-schema, sf-form)
ng-model(添加到sf-model,sf-schema,sf-form)
is bound on the model form, example:
绑定在模型表单上,例如:
ng-model="modelForm" (sf-Model="modelForm")
On your HTML form object ensure that sf-changed
attribute exists with this syntax:
在HTML表单对象上,确保使用以下语法存在sf-changed属性:
sf-changed="onChange"
On the schema object, for the key you want to bind a change event, write:
在架构对象上,对于要绑定更改事件的键,请写入:
{
key: "yourkey",
...blabla...waouou...
x-schema-form: {
onChange: function () { console.log('now it runs'); }
}
}
I debugged the sfChanged directive, and now your change event is triggered.
我调试了sfChanged指令,现在触发了更改事件。
Alone on the form object your change event is not recognized.
单独在表单对象上,您的更改事件无法识别。
The 'on blur option' runs personally and I discover the tool and I cry "why me?" "why so much hate?"
'on blur选项'是亲自运行的,我发现了这个工具,我哭了“为什么是我?” “为什么这么讨厌?”
The documentation has a big hole, have a nice day.
文档有一个大洞,祝你有个愉快的一天。
#1
1
You added onChange in a wrong place. it should be not in schema but in form. check this one http://plnkr.co/edit/h02XKqF3Vc6eefTOEN8m?p=preview
你在错误的地方添加了onChange。它应该不是在架构中而是在形式上。检查这个http://plnkr.co/edit/h02XKqF3Vc6eefTOEN8m?p=preview
$scope.form = [
"name",
"student",
{
key: "email",
onChange: function(modelValue, form) {
console.log("email changed");
console.debug(modelValue);
console.debug(form);
}
},
"title",
{
type: "submit",
title: "Save"
}
];
Though for email field event is not triggered until you enter valid value. not sure if it should work like that.
虽然在输入有效值之前不会触发电子邮件字段事件。不确定它是否应该像那样工作。
You're also missing angular-schema-form tag because this question is related to that particular library.
您还缺少angular-schema-form标记,因为此问题与该特定库有关。
BR
#2
1
I had a look on the sfChanged directive. Unfortunately...
我看了一下sfChanged指令。不幸...
I didn't want to spend a lot of time to just bind a change event. Maybe this tool is not serious...
我不想花很多时间来绑定更改事件。也许这个工具不严肃......
To plug the change event logic, on your html form object ensure that:
要插入更改事件逻辑,请在html表单对象上确保:
ng-model (add to sf-model, sf-schema, sf-form)
ng-model(添加到sf-model,sf-schema,sf-form)
is bound on the model form, example:
绑定在模型表单上,例如:
ng-model="modelForm" (sf-Model="modelForm")
On your HTML form object ensure that sf-changed
attribute exists with this syntax:
在HTML表单对象上,确保使用以下语法存在sf-changed属性:
sf-changed="onChange"
On the schema object, for the key you want to bind a change event, write:
在架构对象上,对于要绑定更改事件的键,请写入:
{
key: "yourkey",
...blabla...waouou...
x-schema-form: {
onChange: function () { console.log('now it runs'); }
}
}
I debugged the sfChanged directive, and now your change event is triggered.
我调试了sfChanged指令,现在触发了更改事件。
Alone on the form object your change event is not recognized.
单独在表单对象上,您的更改事件无法识别。
The 'on blur option' runs personally and I discover the tool and I cry "why me?" "why so much hate?"
'on blur选项'是亲自运行的,我发现了这个工具,我哭了“为什么是我?” “为什么这么讨厌?”
The documentation has a big hole, have a nice day.
文档有一个大洞,祝你有个愉快的一天。