本文整理汇总了TypeScript中main/app/forms/validation/formValidator.FormValidator类的典型用法代码示例。如果您正苦于以下问题:TypeScript FormValidator类的具体用法?TypeScript FormValidator怎么用?TypeScript FormValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormValidator类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildRouter
buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
return express.Router()
.get(path + Paths.paymentOptionPage.uri,
...guards,
(req: express.Request, res: express.Response) => {
this.renderView(new Form(this.createModelAccessor().get(res.locals.draft.document).paymentOption), res)
})
.post(path + Paths.paymentOptionPage.uri,
...guards,
FormValidator.requestHandler(PaymentOption, PaymentOption.fromObject),
ErrorHandling.apply(
async (req: express.Request, res: express.Response): Promise<void> => {
const form: Form<PaymentOption> = req.body
if (form.hasErrors()) {
this.renderView(form, res)
} else {
this.createModelAccessor().patch(res.locals.draft.document, model => model.paymentOption = form.model)
this.deleteRedundantData(res, req)
await this.saveDraft(res.locals)
res.redirect(this.buildPostSubmissionUri(path, req, res))
}
}))
}
示例2: Form
/* tslint:disable:no-default-export */
export default express.Router()
.get(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
(req: express.Request, res: express.Response) => {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
res.render(page.associatedView, {
form: new Form(draft.document.statementOfMeans.partnerPension)
})
})
.post(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
FormValidator.requestHandler(PartnerPension),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<PartnerPension> = 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.partnerPension = form.model
await new DraftService().save(draft, user.bearerToken)
if (draft.document.statementOfMeans.disability && draft.document.statementOfMeans.disability.option === DisabilityOption.YES) {
res.redirect(StatementOfMeansPaths.partnerDisabilityPage.evaluateUri({ externalId: externalId }))
示例3: Form
/* tslint:disable:no-default-export */
export default express.Router()
.get(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
(req: express.Request, res: express.Response) => {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
res.render(page.associatedView, {
form: new Form(draft.document.statementOfMeans.cohabiting)
})
})
.post(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
FormValidator.requestHandler(Cohabiting),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<Cohabiting> = 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.cohabiting = form.model
if (form.model.option === CohabitingOption.NO) {
draft.document.statementOfMeans.partnerAge = draft.document.statementOfMeans.partnerDisability =
draft.document.statementOfMeans.partnerSevereDisability = draft.document.statementOfMeans.partnerPension =
undefined
示例4: renderView
})
}
/* tslint:disable:no-default-export */
export default express.Router()
.get(
Paths.courtOfferedSetDatePage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
renderView(new Form(draft.document.acceptCourtOffer), res)
}))
.post(
Paths.courtOfferedSetDatePage.uri,
FormValidator.requestHandler(AcceptCourtOffer, AcceptCourtOffer.fromObject),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const form: Form<AcceptCourtOffer> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
const user: User = res.locals.user
const { externalId } = req.params
draft.document.acceptCourtOffer = form.model
if (draft.document.courtDetermination.rejectionReason || draft.document.formaliseRepaymentPlan) {
delete draft.document.courtDetermination.rejectionReason
delete draft.document.formaliseRepaymentPlan
delete draft.document.settlementAgreement
示例5: renderView
form: form,
totalAmount: StatesPaidHelper.getAlreadyPaidAmount(claim),
paidInFull: !StatesPaidHelper.isAlreadyPaidLessThanAmount(claim)
})
}
/* tslint:disable:no-default-export */
export default express.Router()
.get(Paths.settleClaimPage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
renderView(new Form(draft.document.accepted), res)
}))
.post(
Paths.settleClaimPage.uri,
FormValidator.requestHandler(ClaimSettled, ClaimSettled.fromObject),
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
const form: Form<ClaimSettled> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
draft.document.accepted = form.model
if (form.model.accepted.option === YesNoOption.YES.option) {
draft.document.rejectionReason = undefined
draft.document.freeMediation = undefined
}
await new DraftService().save(draft, res.locals.user.bearerToken)
示例6: catch
})
} catch (err) {
next(err)
}
}
/* tslint:disable:no-default-export */
export default express.Router()
.get(
Paths.signSettlementAgreement.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
renderView(new Form(new DefendantSettlementResponse()), res, next)
}))
.post(
Paths.signSettlementAgreement.uri,
FormValidator.requestHandler(DefendantSettlementResponse),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const form: Form<DefendantSettlementResponse> = req.body
if (form.hasErrors()) {
renderView(form, res, next)
} else {
const claim: Claim = res.locals.claim
const user: User = res.locals.user
if (form.model.option === YesNoOption.YES.option) {
await settlementAgreementClient.countersignSettlementAgreement(claim.externalId, user)
} else {
await settlementAgreementClient.rejectSettlementAgreement(claim.externalId, user)
}
res.redirect(Paths.settlementAgreementConfirmation.evaluateUri({ externalId: claim.externalId }))
示例7: Form
/* tslint:disable:no-default-export */
export default express.Router()
.get(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
(req: express.Request, res: express.Response) => {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
res.render(page.associatedView, {
form: new Form(draft.document.statementOfMeans.partnerAge)
})
})
.post(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
FormValidator.requestHandler(PartnerAge),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<PartnerAge> = 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.partnerAge = form.model
if (form.model.option === PartnerAgeOption.NO) {
draft.document.statementOfMeans.partnerPension = undefined
}
await new DraftService().save(draft, user.bearerToken)
示例8: Form
/* tslint:disable:no-default-export */
export default express.Router()
.get(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
(req: express.Request, res: express.Response) => {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
res.render(page.associatedView, {
form: new Form(draft.document.statementOfMeans.partnerDisability)
})
})
.post(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
FormValidator.requestHandler(PartnerDisability),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<PartnerDisability> = 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.partnerDisability = form.model
if (form.model.option === PartnerDisabilityOption.NO) {
draft.document.statementOfMeans.partnerSevereDisability = undefined
}
await new DraftService().save(draft, user.bearerToken)
示例9: renderView
function renderView (form: Form<IntentionToProceed>, res: express.Response): void {
res.render(Paths.intentionToProceedPage.associatedView,{
form: form
})
}
/* tslint:disable:no-default-export */
export default express.Router()
.get(Paths.intentionToProceedPage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
renderView(new Form(draft.document.intentionToProceed), res)
}))
.post(
Paths.intentionToProceedPage.uri,
FormValidator.requestHandler(IntentionToProceed, IntentionToProceed.fromObject),
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
const form: Form<IntentionToProceed> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
const mediationDraft: Draft<MediationDraft> = res.locals.mediationDraft
const user: User = res.locals.user
if (form.model.proceed === YesNoOption.NO.option && mediationDraft) {
await new DraftService().delete(mediationDraft.id, user.bearerToken)
}
draft.document.intentionToProceed = form.model
await new DraftService().save(draft, user.bearerToken)
示例10: async
})
}
/* tslint:disable:no-default-export */
export default express.Router()
.get(
Paths.willYouTryMediation.uri,
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const draft: Draft<MediationDraft> = res.locals.mediationDraft
renderView(new Form(draft.document.willYouTryMediation), res)
}
)
.post(
Paths.willYouTryMediation.uri,
FormValidator.requestHandler(FreeMediation),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<FreeMediation> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
const draft: Draft<MediationDraft> = res.locals.mediationDraft
const user: User = res.locals.user
draft.document.willYouTryMediation = form.model
if (form.model.option === FreeMediationOption.NO) {
draft.document.youCanOnlyUseMediation = undefined
draft.document.canWeUse = undefined
draft.document.canWeUseCompany = undefined
}