-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add select_one and select_multiple types (#96)
* feat(#55): add select_one and select_multiple * feat(#55): remove gender validator file * feat(#55): update readme * fix(#55): address feedback * fix(#55): address feedback part 2 * test(#55): update test cases * fix(#55): address feedback part 3 * fix(#55): address final feedback * 1.3.5 --------- Co-authored-by: Kenn Sippell <[email protected]> Co-authored-by: paulpascal <[email protected]>
- Loading branch information
1 parent
81115b7
commit ef9f593
Showing
22 changed files
with
186 additions
and
125 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,54 @@ | ||
import {ContactProperty} from '../config'; | ||
import {IValidator} from './validation'; | ||
import ValidatorString from './validator-string'; | ||
import ValidatorSelectOne from './validator-select-one'; | ||
|
||
const DELIMITER = ' '; | ||
|
||
export default class ValidatorSelectMultiple implements IValidator { | ||
|
||
isValid(input: string, property: ContactProperty): boolean | string { | ||
// Verify property.parameter is an object and is not null | ||
if (!property?.parameter || typeof property.parameter !== 'object') { | ||
throw new TypeError(`Expected attribute "parameter" on property ${property.property_name} to be an object.`); | ||
} | ||
|
||
const selectOneValidator = new ValidatorSelectOne(); | ||
const stringValidator = new ValidatorString(); | ||
|
||
const selectedValues = this.parseInput(input, stringValidator); | ||
const invalidValues = selectedValues.filter( | ||
value => !selectOneValidator.isValid(value, property) | ||
); | ||
|
||
if (invalidValues.length > 0) { | ||
return `Invalid values for property "${property.friendly_name}": ${invalidValues.join(', ')}`; | ||
} | ||
|
||
// Check if any values are missing and property is required | ||
if (selectedValues.length === 0 && property.required) { | ||
return 'Value is required'; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
format(input: string): string { | ||
return Array.isArray(input) ? input.join(DELIMITER) : input; | ||
} | ||
|
||
get defaultError(): string { | ||
return `Invalid input. Please use 'space' as delimiter.`; | ||
} | ||
|
||
private parseInput(input: string|string[], stringValidator: ValidatorString): string[] { | ||
if (Array.isArray(input)) { | ||
return input; | ||
} | ||
|
||
return input | ||
.split(DELIMITER) | ||
.map(value => stringValidator.format(value)) | ||
.filter(Boolean); | ||
} | ||
} |
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,29 @@ | ||
import {ContactProperty} from '../config'; | ||
import {IValidator} from './validation'; | ||
import ValidatorString from './validator-string'; | ||
|
||
export default class ValidatorSelectOne implements IValidator { | ||
isValid(input: string, property: ContactProperty): boolean|string { | ||
const stringValidator = new ValidatorString(); | ||
const trimmedInput = stringValidator.format(input); | ||
|
||
if (trimmedInput.length === 0 && property.required) { | ||
return `Value is required`; | ||
} | ||
// Verify property.parameter is an object | ||
if (!property?.parameter || typeof property.parameter !== 'object') { | ||
throw new TypeError(`Expected attribute "parameter" on property ${property.property_name} to be an object.`); | ||
} | ||
|
||
const validValues = Object.keys(property.parameter); | ||
return validValues.includes(trimmedInput); | ||
} | ||
|
||
format(input: string): string { | ||
return input; | ||
} | ||
|
||
get defaultError(): string { | ||
return 'Invalid value selected'; | ||
} | ||
} |
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,10 @@ | ||
{% assign is_multiple = include.prop.type == 'select_multiple' %} | ||
<div class="select is-fullwidth{% if is_multiple %} is-multiple{% endif %}"> | ||
<select name="{{ prop_name }}" {% if is_multiple %}multiple{% endif %}> | ||
{% for params in include.prop.parameter %} | ||
<option value="{{ params[0] }}" {% if data[prop_name] == params[0] or data[prop_name] contains params[0] %}selected{% endif %}> | ||
{{ params[1] }} | ||
</option> | ||
{% endfor %} | ||
</select> | ||
</div> |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
<td | ||
id="{{ include.propertyName }}" | ||
{% if place.validationErrors[include.propertyName] %} | ||
|
Oops, something went wrong.