-
Notifications
You must be signed in to change notification settings - Fork 9
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 #23 from CrowdStrike/fix-value
Fix rendering `name` attribute, reorganize internal types
- Loading branch information
Showing
17 changed files
with
174 additions
and
86 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
ember-headless-form/src/components/-private/control/checkbox.hbs
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,5 @@ | ||
<input | ||
name={{@name}} | ||
type='checkbox' | ||
checked={{@value}} | ||
id={{@fieldId}} | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<input | ||
name={{@name}} | ||
type={{@type}} | ||
value={{@value}} | ||
id={{@fieldId}} | ||
|
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
1 change: 1 addition & 0 deletions
1
ember-headless-form/src/components/-private/control/radio/input.hbs
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,5 @@ | ||
<input | ||
name={{@name}} | ||
type='radio' | ||
value={{@value}} | ||
checked={{@checked}} | ||
|
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
1 change: 1 addition & 0 deletions
1
ember-headless-form/src/components/-private/control/textarea.hbs
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 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,84 @@ | ||
/** | ||
* What the user can pass as @data | ||
*/ | ||
export type UserData = object; | ||
|
||
/** | ||
* The subset of properties of DATA, whose keys are strings (and not number or symbol) | ||
* Only this data is useable in the form | ||
*/ | ||
export type FormData<DATA extends UserData = UserData> = OnlyStringKeys<DATA>; | ||
|
||
/** | ||
* Returns the type of all keys of DATA, that are also strings. Only strings can be used as field @name | ||
*/ | ||
export type FormKey<DATA extends UserData> = keyof DATA & string; | ||
|
||
/** | ||
* Generic interface for all validation errors | ||
*/ | ||
export interface ValidationError<T = unknown> { | ||
type: string; | ||
// @todo does a validator need to add this? we already have the value internally | ||
value: T; | ||
message?: string; | ||
} | ||
|
||
export type ErrorRecord< | ||
DATA extends FormData, | ||
KEY extends FormKey<DATA> = FormKey<DATA> | ||
> = Partial<Record<KEY, ValidationError<DATA[KEY]>[]>>; | ||
|
||
/** | ||
* Callback used for form level validation | ||
*/ | ||
export type FormValidateCallback<DATA extends FormData> = ( | ||
formData: DATA | ||
) => undefined | ErrorRecord<DATA> | Promise<undefined | ErrorRecord<DATA>>; | ||
|
||
/** | ||
* Callback used for field level validation | ||
*/ | ||
export type FieldValidateCallback< | ||
DATA extends FormData, | ||
KEY extends FormKey<DATA> = FormKey<DATA> | ||
> = ( | ||
fieldValue: DATA[KEY], | ||
fieldName: KEY, | ||
formData: DATA | ||
) => | ||
| undefined | ||
| ValidationError<DATA[KEY]>[] | ||
| Promise<undefined | ValidationError<DATA[KEY]>[]>; | ||
|
||
/** | ||
* Internal structure to track used fields | ||
* @private | ||
*/ | ||
export interface FieldData< | ||
DATA extends FormData, | ||
KEY extends FormKey<DATA> = FormKey<DATA> | ||
> { | ||
validate?: FieldValidateCallback<DATA, KEY>; | ||
} | ||
|
||
/** | ||
* For internal field registration | ||
* @private | ||
*/ | ||
export type RegisterFieldCallback< | ||
DATA extends FormData, | ||
KEY extends FormKey<DATA> = FormKey<DATA> | ||
> = (name: KEY, field: FieldData<DATA, KEY>) => void; | ||
|
||
export type UnregisterFieldCallback< | ||
DATA extends FormData, | ||
KEY extends FormKey<DATA> = FormKey<DATA> | ||
> = (name: KEY) => void; | ||
|
||
/** | ||
* Mapper type to construct subset of objects, whose keys are only strings (and not number or symbol) | ||
*/ | ||
export type OnlyStringKeys<T extends object> = { | ||
[P in Extract<keyof T, string>]: T[P]; | ||
}; |
Oops, something went wrong.