На протяжении всего моего приложения я пытался использовать autoform несколько раз, но я думаю, что существует реальный конфликт между автоформами и шаблонами MaterializeCSS. Во всяком случае, я получаю следующие ошибки:
Схема:
import SimpleSchema from 'simpl-schema';
import { Materials } from '/imports/api/materials/materials.js';
import { PurchasesAPI } from '/imports/api/purchases/api.js';
import '../../ui/components/purchasing/purchasing-autocomplete-list-template.html';
export const purchasingCreatePurchaseSchema = new SimpleSchema({
userId: {
type: String,
autoValue: function () {
if (this.isInsert) {
console.log("this is insert");
console.log(Meteor.userId());
return Meteor.userId();
} else if (this.isUpsert) {
return { $setOnInsert: Meteor.userId() };
}
this.unset(); // Prevent user from supplying their own value
return undefined;
},
autoform: {
omit: true
}
},
createdOn: {
type: Date,
// defaultValue: new Date(),
autoValue: function () {
if (this.isInsert) {
return new Date();
}
this.unset(); // Prevent user from supplying their own value
return undefined;
},
autoform: {
omit: true
}
},
purchaseOrderNo: {
type: String,
autoValue: function () {
if (this.isInsert) {
return PurchasesAPI.newPurchaseOrder();
}
this.unset(); // Prevent user from supplying their own value
return undefined;
}
},
orderedDate: {
type: Date,
autoform: {
afFieldInput: {
class: 'datepicker'
}
}
},
supplier: {
type: String,
defaultValue: "Not Specified"
},
material: {
type: String,
autoform: {
afFieldInput: {
type: 'autocomplete-input',
placeholder: 'Material',
settings: function () {
return {
position: "top",
limit: 20,
rules: [
{
collection: Materials,
field: "material",
matchAll: true,
template: Template.Purchasing_material_item
}
]
}
}
}
}
},
orderConfirmationDate: {
type: Date,
optional: true,
autoform: {
afFieldInput: {
class: 'datepicker'
}
}
},
estimatedTimeOfArrival: {
type: Date,
optional: true,
autoform: {
afFieldInput: {
class: 'datepicker'
}
}
},
actualTimeOfArrival: {
type: Date,
optional: true,
autoform: {
afFieldInput: {
class: 'datepicker'
}
}
}
});
HTML
{{> quickForm schema=createPurchaseSchema id="createNewPurchase" type="normal" buttonContent="false"}}
Когда нажата кнопка отправки, я получаю:
VM32227 aldeed_autoform.js:7702 Uncaught TypeError: ec.invalidKeys is not a function
at failedValidation (VM32227 aldeed_autoform.js:7702)
at Object.autoFormSubmitHandler (VM32227 aldeed_autoform.js:7836)
at VM32193 blaze.js:3775
at Function.Template._withTemplateInstanceFunc (VM32193 blaze.js:3744)
at Blaze.View.<anonymous> (VM32193 blaze.js:3774)
at VM32193 blaze.js:2617
at Object.Blaze._withCurrentView (VM32193 blaze.js:2271)
at Blaze._DOMRange.<anonymous> (VM32193 blaze.js:2616)
at HTMLFormElement.<anonymous> (VM32193 blaze.js:863)
at HTMLDivElement.dispatch (VM32156 modules.js:17882)
failedValidation @ VM32227 aldeed_autoform.js:7702
autoFormSubmitHandler @ VM32227 aldeed_autoform.js:7836
(anonymous) @ VM32193 blaze.js:3775
Template._withTemplateInstanceFunc @ VM32193 blaze.js:3744
(anonymous) @ VM32193 blaze.js:3774
(anonymous) @ VM32193 blaze.js:2617
Blaze._withCurrentView @ VM32193 blaze.js:2271
(anonymous) @ VM32193 blaze.js:2616
(anonymous) @ VM32193 blaze.js:863
dispatch @ VM32156 modules.js:17882
elemData.handle @ VM32156 modules.js:17690
Navigated to http://localhost:3000/purchasing/purchases/new-purchase?purchaseOrderNo=&orderedDate=&supplier=Not+Specified&material=&orderConfirmationDate=&estimatedTimeOfArrival=&actualTimeOfArrival=
Мои крючки тоже не стреляют, если я попытаюсь перезаписать кнопку отправки с помощью Template.Purchasing_new_purchase_form.events({ 'submit': function() {...} })
Это тоже не сработает.
Если кто-то может мне помочь, я был бы очень благодарен и, надеюсь, я смогу использовать больше автоформ в своем приложении, но в настоящее время я просто закодировал форму с нуля, а затем применил ручную проверку без реактивной проверки. Является ли это неотъемлемой проблемой для AutoForm или просто что-то, что я делаю неправильно?
Удалось решить эту проблему!
Я обновил Autoform to 6.3.0
, Simple-schema
до> 1.4, удалил все другие связанные пакеты автоформ, такие как autocomplete
, и autoform-materialize
и autoform-materialize
вещи.
"aldeed:autoform 5.8.1*, "simpl-schema": "^0.3.2"
иmpowaga:autoform-autocomplete
autocomplete 0.0.2 ', без использованияcollection2-core
.