forked from XGovFormBuilder/digital-form-builder
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from ukhsa-collaboration/feat/OOC-4405
OOC-4405: Update landing page (part 2) content (CQC checkbox)
- Loading branch information
Showing
10 changed files
with
188 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
runner/src/server/plugins/engine/components/TextFieldCustom.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { TextFieldCustomComponent } from "@xgovformbuilder/model"; | ||
import { FormModel } from "../models"; | ||
import joi from "joi"; | ||
import * as helpers from "./helpers"; | ||
import { FormPayload } from "../types"; | ||
import { FormComponent } from "./FormComponent"; | ||
|
||
// Currently only used on the ReportAnOutbreak/uon-and-cqc page to handle textfield and checkbox comparisons | ||
export class TextFieldCustom extends FormComponent { | ||
formSchema; | ||
stateSchema; | ||
pattern; | ||
dependentField; | ||
fieldName; | ||
|
||
constructor(def: TextFieldCustomComponent, model: FormModel) { | ||
super(def, model); | ||
|
||
const { options, schema = {} } = def; | ||
this.options = options; | ||
this.schema = schema; | ||
|
||
if (schema.regex) { | ||
this.pattern = new RegExp(schema.regex); | ||
} | ||
|
||
if (options.conditionalTextField) { | ||
this.dependentField = options.conditionalTextField.dependsOn; | ||
} | ||
|
||
if (options.fieldName) { | ||
this.fieldName = options.fieldName; | ||
} | ||
|
||
let componentSchema = joi.optional().allow(null).allow(""); | ||
|
||
this.formSchema = componentSchema; | ||
} | ||
|
||
getStateSchemaKeys() { | ||
let schema: any = this.formSchema; | ||
|
||
if (this.fieldName) { | ||
schema = schema.custom( | ||
helpers.customTextCheckboxValidator(this.fieldName) | ||
); | ||
} | ||
|
||
this.schema = schema; | ||
return { [this.name]: schema }; | ||
} | ||
|
||
getStateValueFromValidForm(payload: FormPayload) { | ||
const currentFieldValue = payload[this.name].trim(); | ||
const dependentFieldValue = payload[this.dependentField]; | ||
|
||
if (currentFieldValue === "" && !dependentFieldValue) { | ||
return false; | ||
} | ||
if (currentFieldValue && !this.pattern.test(currentFieldValue)) { | ||
return "regex"; | ||
} | ||
return currentFieldValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
runner/src/server/plugins/engine/views/components/textfieldcustom.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% from "input/macro.njk" import govukInput %} | ||
|
||
{% macro TextFieldCustom(component) %} | ||
{{ govukInput(component.model) }} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters