我跟着Start Date to be Greater than End Date鏈接。以下是SimpleSchema
的代碼。SimpleSchema autoform 6.2.0中的自定義錯誤消息不起作用
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import MessageBox from 'message-box';
SimpleSchema.extendOptions(['autoform']);
MessageBox.defaults({
en: {
startDateMustBeSmaller: "From Date must be greater than to Date"
}
});
export const Appointments = new Mongo.Collection('Appointments');
Appointments.allow({
insert: function(userId, doc){ return !!userId; },
update: function(userId, doc){ return !!userId; },
remove: function(userId, doc){ return !!userId; }
});
AppointmentsSchema = new SimpleSchema({
"fromDate": {
type: Date,
label: "From Date",
autoform: {
afFieldInput: {
type: "text",
}
}
},
"toDate": {
type: Date,
label: "To Date",
autoform: {
afFieldInput: {
type: "text",
}
},
custom: function() {
var start = this.field('fromDate');
var end = this;
if (start.isSet && end.isSet) {
if (moment(end.value).isBefore(start.value)) return "startDateMustBeSmaller";
}
}
}
});
Appointments.attachSchema(AppointmentsSchema);
Template.html
{{#autoForm id='insertAppointmentForm' collection=appointment type="insert" doc=this validation="browser"}}
<fieldset>
<div class="col-sm-6">
{{> afQuickField name='clientId' options=clientsSelect2 select2Options=s2Opts}}
</div>
<div class="col-sm-6">
{{> afQuickField name='otherDetails'}}
</div>
<div class="col-sm-6">
{{> afQuickField name='fromDate'}}
</div>
<div class="col-sm-6">
{{> afQuickField name='toDate'}}
</div>
<div class="col-sm-6">
{{> afQuickField name='reason'}}
</div>
<div class="col-sm-6">
{{> afQuickField name='meetingType'}}
</div>
</fieldset>
<div>
<button type="submit" class="btn btn-sm bg-olive margin">
<span class="glyphicon glyphicon-ok"></span> Create
</button>
<button type="submit" class="btn btn-sm bg-navy margin reset">
<span class="glyphicon glyphicon-refresh"></span> Reset
</button>
<a href="/user/view-appointments" class="btn btn-sm bg-orange margin pull-right" role="button">
<span class="glyphicon glyphicon-eye-open"></span>
View Appointments
</a>
</div>
{{/autoForm}}
當我嘗試與上述模式運行,形式沒有得到提交,無論是客戶端或服務器錯誤。
我也試過SimpleSchema.messages({})
,SimpleSchema.messageBox.messages({})
但我得到method not found error.
問題:我想檢查是否結束日期之前開始日期。以上代碼不起作用。
注:我使用流星1.5.0
aldeed:[email protected]
,"simpl-schema": "^0.3.2"
仍然無效。頁面掛起。服務器或客戶端沒有錯誤。 –
@AnkurSoni你是什麼意思的「頁面掛起」?用戶界面無響應? – Styx
我的意思是沒有行動發生,表單是正常的,即我仍然可以把正確的條目,它的工作原理。但是當我把錯誤的日期,沒有行動發生。 –