当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript formValidator.FormValidator类代码示例

本文整理汇总了TypeScript中forms/validation/formValidator.FormValidator的典型用法代码示例。如果您正苦于以下问题:TypeScript FormValidator类的具体用法?TypeScript FormValidator怎么用?TypeScript FormValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FormValidator类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: buildRouter

  buildRouter (): express.Router {

    return express.Router()
      .get(Paths.repaymentPlanPage.uri,
        ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
          const draft: Draft<DraftCCJ> = res.locals.ccjDraft
          this.renderView(new Form(draft.document.repaymentPlan), res)
        }))
      .post(Paths.repaymentPlanPage.uri,
        FormValidator.requestHandler(RepaymentPlan, RepaymentPlan.fromObject),
        ErrorHandling.apply(
          async (req: express.Request, res: express.Response): Promise<void> => {
            let form: Form<PaidAmount> = req.body
            const error: FormValidationError = this.postValidation(req, res)

            if (error) {
              form = new Form<PaidAmount>(form.model, [error, ...form.errors])
            }

            if (form.hasErrors()) {
              this.renderView(form, res)
            } else {

              res.locals.draft.document.repaymentPlan = form.model
              res.locals.draft.document.payBySetDate = undefined
              await this.saveDraft(res.locals)

              res.redirect(this.buildPostSubmissionUri(req, res))
            }
          })
      )
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:32,代码来源:repayment-plan.ts

示例2: buildRouter

  buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
    return express.Router()
      .get(
        path + FreeMediationPaths.freeMediationPage.uri,
        ...guards,
        (req: express.Request, res: express.Response) => {
          const draft: Draft<any> = res.locals.draft

          this.renderView(new Form(draft.document.freeMediation), res)
        })
      .post(
        path + FreeMediationPaths.freeMediationPage.uri,
        ...guards,
        FormValidator.requestHandler(FreeMediation),
        ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
          const form: Form<FreeMediation> = req.body

          if (form.hasErrors()) {
            this.renderView(form, res)
          } else {
            const draft: Draft<any> = res.locals.draft
            const user: User = res.locals.user

            draft.document.freeMediation = form.model
            await new DraftService().save(draft, user.bearerToken)

            res.redirect(this.buildRedirectUri(req, res))
          }
        }))
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:30,代码来源:free-mediation.ts

示例3: buildRouter

  buildRouter (): express.Router {
    return express.Router()
      .get(this.path.uri, (req: express.Request, res: express.Response): void => {
        this.renderView(new Form(eligibilityStore.read(req, res)), res)
      })
      .post(this.path.uri,
        FormValidator.requestHandler(undefined, Eligibility.fromObject, this.property),
        ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
          const form: Form<Eligibility> = req.body

          if (form.hasErrors()) {
            this.renderView(form, res)
          } else {
            let eligibility: Eligibility = eligibilityStore.read(req, res)
            if (eligibility === undefined) {
              eligibility = new Eligibility()
            }

            eligibility[this.property] = form.model[this.property]
            eligibilityStore.write(eligibility, req, res)

            this.handleAnswer(eligibility[this.property], res)
          }
        })
      )
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:26,代码来源:eligibilityPage.ts

示例4: buildRouter

  buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
    return express.Router()
      .get(
        path + Paths.paidAmountPage.uri,
        ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
          this.renderView(new Form(this.paidAmount().get(res.locals.draft.document)), res)
        }))
      .post(
        path + Paths.paidAmountPage.uri,
        FormValidator.requestHandler(PaidAmount, PaidAmount.fromObject),
        ErrorHandling.apply(
          async (req: express.Request, res: express.Response): Promise<void> => {
            const form: Form<PaidAmount> = req.body

            if (form.hasErrors()) {
              this.renderView(form, res)
            } else {
              this.paidAmount().set(res.locals.draft.document, form.model)

              const user: User = res.locals.user
              await new DraftService().save(res.locals.draft, user.bearerToken)

              const { externalId } = req.params
              res.redirect(new RoutablePath(path + Paths.paidAmountSummaryPage.uri).evaluateUri({ externalId: externalId }))
            }
          }))
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:27,代码来源:paid-amount.ts

示例5: it

  it('should not validate deserialized object when action is whitelisted', () => {
    req.body = { action: { reload: 'Reload page' } }

    FormValidator.requestHandler(Party, null, undefined, ['reload'])(req, res, next)

    chai.expect(req.body.errors.length).to.be.equal(0)
  })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:7,代码来源:formValidator.ts

示例6: buildRouter

  buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
    const stateGuardRequestHandler: express.RequestHandler = GuardFactory.create((res: express.Response): boolean => {
      const model: PaymentIntention = this.createModelAccessor().get(res.locals.draft.document)

      return model
        && model.paymentOption
        && model.paymentOption.isOfType(PaymentType.INSTALMENTS)
    }, (req: express.Request, res: express.Response): void => {
      throw new NotFoundError(req.path)
    })

    return express.Router()
      .get(path + Paths.paymentPlanPage.uri,
        ...guards,
        stateGuardRequestHandler,
        ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
          this.renderView(new Form(this.createModelAccessor().get(res.locals.draft.document).paymentPlan), res)
        }))
      .post(path + Paths.paymentPlanPage.uri,
        ...guards,
        stateGuardRequestHandler,
        FormValidator.requestHandler(PaymentPlanModel, PaymentPlanModel.fromObject, undefined, ['calculatePaymentPlan']),
        ErrorHandling.apply(
          async (req: express.Request, res: express.Response): Promise<void> => {
            let form: Form<PaymentPlanModel> = req.body

            const error: FormValidationError = this.postValidation(req, res)

            if (error) {
              form = new Form<PaymentPlanModel>(form.model, [error, ...form.errors])
            }

            if (form.hasErrors() || _.get(req, 'body.action.calculatePaymentPlan')) {
              this.renderView(form, res)
            } else {
              this.createModelAccessor().patch(res.locals.draft.document, model => model.paymentPlan = form.model)

              await this.saveDraft(res.locals)

              res.redirect(this.buildPostSubmissionUri(req, res))
            }
          }))
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:43,代码来源:payment-plan.ts


注:本文中的forms/validation/formValidator.FormValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。