0
我有一個order
模型,我正在通過多頁表單收集數據。我已經創造了一些驗證這樣的:在多頁面表單中使用ember-cp驗證
const Validations = buildValidations({
// these should only be used when we’re on checkout.info route
name: validator('presence', true),
email: [
validator('presence', true),
validator('format', { type: 'email' })
],
// these should only be used when we’re on checkout.shipping route
address1: validator('presence', true),
address2: validator('presence', true),
city: validator('presence', true),
});
我的模型被設置爲使用它們像這樣:
export default Model.extend(Validations, {
// model set-up in here
})
我想發生的是它僅驗證name
和email
當我在checkout.info
上時,驗證address1
,address2
和city
,當我在checkout.shipping
上時。
有一個問題我已經試過已經在運行驗證我checkout-form
組件裏面的東西:
let { m, validations } = order.validateSync({
on: ['name', 'email']
})
const isValid = validations.get('isValid')
order.set('didValidate', isValid)
的問題是,這似乎並沒有解除對我的窗體的下一個按鈕
禁用狀態{{next-button disabled=(v-get model.order 'isInvalid')}}
我想另一件事是建立一個自定義的驗證routed-presence
禁用presence
時,它不是目前的路線上。這樣做的麻煩在於其他驗證器仍然會阻止這個(例如類型或長度)。
我該如何去做到這一點?
很好,謝謝!我會如何將當前的路線信息傳遞到我的模型中?例如能夠檢查像'computed.equal('model.currentPath','checkout.shipping')'? – gosseti
我已經添加了'step:attr('string')'到我的'訂單'模型。在我的'checkout-form'組件中,我做了'this.get('model.order')。setProperties({step:this.get('router.currentPath')})',然後'disabled:!computed .equal('model.step','checkout.shipping')'在我的驗證中。它似乎沒有工作,但...我做了什麼顯然是錯誤的? – gosseti
相信你需要使用第二個計算屬性'disabled:computed.not()'或者一個自定義的計算屬性,我不認爲你可以像你在做的那樣否定... – acorncom