我正在使用Ember3.15(辛烷),并试图通过遵循他们的github上的示例来让ember-changeset-validations工作,但很难让它得到验证。控制台中没有(与代码相关的)错误,但changeset.isValid总是返回true。
{{! application/controller.js}}
import {action} from "@ember/object";
import MyValidationClass from '../Validations/myValidations';
export default class MyController extends Controller {
MyValidationClass;
@action
submit(changeset) {
changeset.save()
}
}--
{{! application/template.hbs}}
<MyComponent
@changeset={{changeset this.model this.MyValidationClass}}
@onSubmit={{this.submit}}
/>--
{{! application/components/mycomponent.hbs}}
<BsForm @formLayout="horizontal" {{on 'submit' (fn this.submit @changeset)}} @model={{@changeset}} as |form|>
<form.element
@controlType="text"
@label="Title"
@placeholder="Title"
@property="title"
@required={{true}}
/>
</BsForm>--
{{! application/components/mycomponent.js}}
export default class MyComponent extends Component {
async submit(changeset) {
await changeset.validate();
if(changeset.isValid) // returns true even when the validation should fail
this.args.onSubmit(changeset);
}
}--
{{! application/Validations/myValidations.js}}
import {
validateLength,
validatePresence
} from 'ember-changeset-validations/validators';
export default {
title: [
validatePresence(true),
validateLength({ min: 44 })
]
};发布于 2020-01-23 14:35:26
好的,通过github issue找到了帮助
基本上,在控制器中,更改
MyValidationClass;类似这样的东西
MyValidationClass = MyValidationClass;否则,MyValidationClass将被设置为undefined
https://stackoverflow.com/questions/59807748
复制相似问题