本文整理匯總了TypeScript中forms/form.Form類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Form類的具體用法?TypeScript Form怎麽用?TypeScript Form使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Form類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<Disability> = req.body
const { externalId } = req.params
if (form.hasErrors()) {
res.render(page.associatedView, { form: form })
} else {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
const user: User = res.locals.user
draft.document.statementOfMeans.disability = form.model
if (form.model.option === DisabilityOption.NO) {
draft.document.statementOfMeans.severeDisability = undefined
}
await new DraftService().save(draft, user.bearerToken)
if (form.model.option === DisabilityOption.YES) {
res.redirect(StatementOfMeansPaths.severeDisabilityPage.evaluateUri({ externalId: externalId }))
} else {
res.redirect(StatementOfMeansPaths.residencePage.evaluateUri({ externalId: externalId }))
}
}
})
示例2: saveAndRedirect
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
const form: Form<AcceptCourtOffer> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
draft.document.acceptCourtOffer = form.model
const { externalId } = req.params
if (form.model.accept.option === YesNoOption.YES.option) {
draft.document.settlementAgreement = undefined
draft.document.formaliseRepaymentPlan = undefined
draft.document.courtDetermination.rejectionReason = undefined
await saveAndRedirect(res, draft, ClaimantsResponsePaths.taskListPage.evaluateUri({ externalId: externalId }))
} else {
await saveAndRedirect(res, draft, ClaimantsResponsePaths.rejectionReasonPage.evaluateUri({ externalId: externalId }))
}
}
}
示例3: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const form: Form<AlreadyPaid> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
const user: User = res.locals.user
draft.document.partialAdmission.alreadyPaid = form.model
draft.document.fullAdmission = draft.document.rejectAllOfClaim = undefined
if (draft.document.partialAdmission.alreadyPaid.option === YesNoOption.YES) {
draft.document.partialAdmission.howMuchDoYouOwe = undefined
} else {
draft.document.partialAdmission.howMuchHaveYouPaid = undefined
}
await new DraftService().save(draft, user.bearerToken)
const { externalId } = req.params
res.redirect(Paths.taskListPage.evaluateUri({ externalId: externalId }))
}
}))
示例4: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const form: Form<CanWeUse> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const claim: Claim = res.locals.claim
const draft: Draft<MediationDraft> = res.locals.mediationDraft
const user: User = res.locals.user
draft.document.canWeUse = form.model
if (form.model.option === FreeMediationOption.YES) {
draft.document.canWeUse.mediationPhoneNumber = undefined
}
await new DraftService().save(draft, user.bearerToken)
if (!claim.isResponseSubmitted()) {
res.redirect(ResponsePaths.taskListPage.evaluateUri({ externalId: claim.externalId }))
} else {
res.redirect(ClaimantResponsePaths.taskListPage.evaluateUri({ externalId: claim.externalId }))
}
}
})
示例5: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const form: Form<InterestContinueClaiming> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<DraftClaim> = res.locals.claimDraft
const user: User = res.locals.user
draft.document.interestContinueClaiming = form.model
if (form.model.option === YesNoOption.NO) {
draft.document.interestHowMuch = undefined
}
await new DraftService().save(draft, user.bearerToken)
if (form.model.option === YesNoOption.NO) {
res.redirect(Paths.totalPage.uri)
} else {
res.redirect(Paths.interestHowMuchPage.uri)
}
}
}))
示例6: ValidationError
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<HowMuchOwed> = req.body
const claim: Claim = res.locals.claim
const user: User = res.locals.user
if (form.model.amount > claim.totalAmountTillToday) {
let totalAmount: string = NumberFormatter.formatMoney(claim.totalAmountTillToday)
let error = new ValidationError()
error.property = 'amount'
error.constraints = { amount: 'Enter a valid amount between ÂŁ1 and ' + totalAmount }
form.errors.push(new FormValidationError(error))
}
if (form.hasErrors()) {
await renderView(form, res, next)
} else {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
draft.document.howMuchOwed = form.model
await new DraftService().save(draft, user.bearerToken)
res.redirect(Paths.timelinePage.evaluateUri({ externalId: claim.externalId }))
}
})
示例7: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<InterestDate> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<DraftClaim> = res.locals.claimDraft
const user: User = res.locals.user
draft.document.interestDate = form.model
if (form.model.type === InterestDateType.SUBMISSION) {
draft.document.interestStartDate = undefined
draft.document.interestEndDate = undefined
}
await new DraftService().save(draft, user.bearerToken)
if (form.model.type === InterestDateType.SUBMISSION) {
res.redirect(Paths.totalPage.uri)
} else {
res.redirect(Paths.interestStartDatePage.uri)
}
}
}))
示例8: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
const form: Form<OtherDependants> = req.body
const { externalId } = req.params
if (form.hasErrors()) {
res.render(page.associatedView, { form: form })
} else {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
const user: User = res.locals.user
draft.document.statementOfMeans.otherDependants = form.model
// skip if any dependants are disabled, or if defendant and partner are both disabled, or if defendant is severely disabled
const anyDisabledDependants: boolean =
(draft.document.statementOfMeans.dependantsDisability && draft.document.statementOfMeans.dependantsDisability.option === DependantsDisabilityOption.YES)
|| (draft.document.statementOfMeans.otherDependantsDisability && draft.document.statementOfMeans.otherDependantsDisability.option === OtherDependantsDisabilityOption.YES)
const defendantIsDisabled: boolean = draft.document.statementOfMeans.disability.option === DisabilityOption.YES
const partnerIsDisabled: boolean = draft.document.statementOfMeans.cohabiting.option === CohabitingOption.YES
&& draft.document.statementOfMeans.partnerDisability.option === PartnerDisabilityOption.YES
const defendantIsSeverelyDisabled: boolean = draft.document.statementOfMeans.severeDisability
&& draft.document.statementOfMeans.severeDisability.option === SevereDisabilityOption.YES
const skipCarerPage: boolean = anyDisabledDependants || (defendantIsDisabled && partnerIsDisabled) || defendantIsSeverelyDisabled
if (skipCarerPage) {
draft.document.statementOfMeans.carer = undefined
}
await new DraftService().save(draft, user.bearerToken)
if (skipCarerPage) {
res.redirect(Paths.employmentPage.evaluateUri({ externalId: externalId }))
} else {
res.redirect(Paths.carerPage.evaluateUri({ externalId: externalId }))
}
}
})
示例9: it
it('should return value if value associated with given field exists', () => {
const form: Form<any> = new Form({ address: { city: 'London' } })
expect(form.valueFor('address[city]')).to.equal('London')
})
示例10: renderView
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
renderView(Form.empty<ClaimReference>(), res)
})