-
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.
- Loading branch information
Showing
7 changed files
with
94 additions
and
55 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
24 changes: 24 additions & 0 deletions
24
src/app/pages/registration/formly/disable-prefilled.extension.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,24 @@ | ||
import { FormlyExtension, FormlyFieldConfig } from '@ngx-formly/core'; | ||
|
||
/** | ||
* This extension disables all fields that have keys that match those | ||
* specified in the formstate.disabled property | ||
*/ | ||
type FieldConfigWithDisabled = Omit<FormlyFieldConfig, 'options'> & { options: { formState: { disabled: string[] } } }; | ||
|
||
export const disablePrefilledExtension: FormlyExtension = { | ||
prePopulate: field => { | ||
if (hasDisabled(field) && field.key) { | ||
field.templateOptions = { ...field.templateOptions }; | ||
field.templateOptions.disabled = field.options.formState.disabled.includes(field.key as string); | ||
} | ||
}, | ||
}; | ||
|
||
function hasDisabled(field: FormlyFieldConfig): field is FieldConfigWithDisabled { | ||
return ( | ||
Array.isArray(field.options?.formState?.disabled) && | ||
// tslint:disable-next-line: no-any | ||
(field.options.formState.disabled as any[]).reduce((acc, val) => acc && typeof val === 'string', true) | ||
); | ||
} |
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
0245f2e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Azure Demo Servers are available: