Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
feat(single-select): add option to force array output for single-sele…
Browse files Browse the repository at this point in the history
…ct mode
  • Loading branch information
Philipp Burgmer committed Sep 25, 2017
1 parent 5d358cd commit 95975af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/model/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class ConfigInstance {
hideCheckboxes: boolean = false;
/** single or multiple select */
multiple: boolean = true;
/** force ngModel to be an array for single select too */
forceArrayOutput = false;
/** disable user interaction */
disabled: boolean = false;
/** all the configuration for the header (visible if dropdown closed) */
Expand Down
20 changes: 13 additions & 7 deletions src/w11k-select.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export function w11kSelect (w11kSelectConfig: Config,

let modelValue;

if (scope.config.multiple) {
if (scope.config.multiple || scope.config.forceArrayOutput) {
modelValue = viewValue;
} else {
modelValue = viewValue[0];
Expand All @@ -531,12 +531,18 @@ export function w11kSelect (w11kSelectConfig: Config,
return modelValue;
}

function validateRequired(viewValue) {
if (scope.config.multiple === true && scope.config.required === true && viewValue.length === 0) {
return false;
}
if (scope.config.multiple === false && scope.config.required === true && viewValue === undefined) {
return false;
function validateRequired (value): boolean {
if (scope.config.required) {
if (scope.config.multiple === true && value.length === 0) {
return false;
}
if (scope.config.multiple === false && scope.config.forceArrayOutput === true && value.length === 0) {
return false;
}
if (scope.config.multiple === false && value === undefined) {
return false;
}

}

return true;
Expand Down

0 comments on commit 95975af

Please sign in to comment.