-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add uen field in public frontend * add essential uen types * make sure uen field renders * replace isUenValid with isUenField
- Loading branch information
1 parent
51dbbe7
commit 35eeeaf
Showing
18 changed files
with
321 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Schema } from 'mongoose' | ||
|
||
import { IUenFieldSchema } from '../../../types' | ||
|
||
const createUenFieldSchema = () => new Schema<IUenFieldSchema>() | ||
|
||
export default createUenFieldSchema |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { chain, left, right } from 'fp-ts/lib/Either' | ||
import { flow } from 'fp-ts/lib/function' | ||
|
||
import { ProcessedSingleAnswerResponse } from 'src/app/modules/submission/submission.types' | ||
import { ResponseValidator } from 'src/types/field/utils/validation' | ||
|
||
import { isUenValid } from '../../../../shared/util/uen-validation' | ||
|
||
import { notEmptySingleAnswerResponse } from './common' | ||
|
||
type UenValidator = ResponseValidator<ProcessedSingleAnswerResponse> | ||
type UenValidatorConstructor = () => UenValidator | ||
|
||
/** | ||
* Returns a validator to check if uen | ||
* format is correct. | ||
*/ | ||
const uenValidator: UenValidator = (response) => { | ||
return isUenValid(response.answer) | ||
? right(response) | ||
: left(`UenValidator:\tanswer is not a valid UEN`) | ||
} | ||
|
||
/** | ||
* Returns a validation function for a uen field when called. | ||
*/ | ||
export const constructUenValidator: UenValidatorConstructor = () => | ||
flow(notEmptySingleAnswerResponse, chain(uenValidator)) |
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
56 changes: 56 additions & 0 deletions
56
src/public/modules/forms/base/componentViews/field-uen.client.view.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,56 @@ | ||
<div class="text-field field-group row"> | ||
<!-- Question --> | ||
<label | ||
for="{{ vm.field._id || 'defaultID'}}" | ||
class="field-question col-xs-12" | ||
> | ||
<div id="label-{{ vm.field._id || 'defaultID'}}"> | ||
<span class="field-number" ng-show="vm.field.field_number" | ||
>{{ vm.field.field_number }}.</span | ||
> | ||
<span class="field-title">{{ vm.field.title }}</span> | ||
<span class="field-optional" ng-if="!vm.field.required">(optional)</span> | ||
</div> | ||
<div | ||
id="description-{{ vm.field._id || 'defaultID'}}" | ||
class="field-description" | ||
ng-if="vm.field.description" | ||
ng-bind-html="vm.field.description | linky:'_blank'" | ||
></div> | ||
</label> | ||
|
||
<!-- Input --> | ||
<div class="col-xs-12 field-input"> | ||
<input | ||
id="{{ vm.field._id || 'defaultID'}}" | ||
type="text" | ||
name="{{ vm.field._id || 'defaultID'}}" | ||
class="input-custom input-large" | ||
ng-model="vm.field.fieldValue" | ||
ng-required="vm.field.required" | ||
ng-disabled="vm.field.disabled" | ||
ng-model-options="{ allowInvalid: true }" | ||
ng-keyup="vm.forms.myForm[(vm.field._id || 'defaultID')].$setTouched()" | ||
placeholder="Enter UEN" | ||
autocomplete="off" | ||
ng-trim="true" | ||
ng-class="vm.field.disabled && vm.field.fieldValue ? 'myinfo-disable' : ''" | ||
aria-labelledby="label-{{ vm.field._id || 'defaultID'}}" | ||
aria-describedby="description-{{ vm.field._id || 'defaultID'}}" | ||
validate-uen | ||
/> | ||
</div> | ||
|
||
<!-- Error --> | ||
<div | ||
class="col-xs-12" | ||
ng-show="vm.forms.myForm[(vm.field._id || 'defaultID')].$touched" | ||
ng-messages="vm.forms.myForm[(vm.field._id || 'defaultID')].$error" | ||
> | ||
<field-error-component ng-message="required"></field-error-component> | ||
<div ng-message="uenValidator" class="alert-custom alert-error"> | ||
<i class="bx bx-exclamation bx-md icon-spacing"></i> | ||
<span class="alert-msg">Please enter a valid UEN</span> | ||
</div> | ||
</div> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
src/public/modules/forms/base/components/field-uen.client.component.js
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,10 @@ | ||
'use strict' | ||
|
||
angular.module('forms').component('uenFieldComponent', { | ||
templateUrl: 'modules/forms/base/componentViews/field-uen.client.view.html', | ||
bindings: { | ||
field: '<', | ||
forms: '<', | ||
}, | ||
controllerAs: 'vm', | ||
}) |
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
17 changes: 17 additions & 0 deletions
17
src/public/modules/forms/base/directives/validate-uen.client.directive.js
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,17 @@ | ||
'use strict' | ||
|
||
const { isUenValid } = require('../../../../../shared/util/uen-validation') | ||
|
||
angular.module('forms').directive('validateUen', validateUen) | ||
|
||
function validateUen() { | ||
return { | ||
restrict: 'A', | ||
require: 'ngModel', | ||
link: function (_scope, _elem, _attrs, ctrl) { | ||
ctrl.$validators.uenValidator = function (modelValue) { | ||
return ctrl.$isEmpty(modelValue) ? true : isUenValid(modelValue) | ||
} | ||
}, | ||
} | ||
} |
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
Oops, something went wrong.