-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(components/forms): file drop add control value accessor #2968
base: 11.x.x
Are you sure you want to change the base?
Changes from all commits
459e7d3
4fa47c9
5178eeb
4c0d79c
a01f43b
dbee987
5167763
bb9fc16
19bb797
d5064c9
89e5e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
<sky-file-drop | ||
linkUploadHintText="Start with http:// or https://" | ||
[acceptedTypes]="acceptedTypes" | ||
[allowLinks]="true" | ||
[hintText]="hintText" | ||
[helpPopoverContent]="inlineHelpContent" | ||
[labelText]="labelText" | ||
[maxFileSize]="maxFileSize" | ||
[required]="required" | ||
[stacked]="stacked" | ||
[validateFn]="validateFile" | ||
(filesChanged)="onFilesChanged($event)" | ||
(linkChanged)="onLinkChanged($event)" | ||
/> | ||
@for (file of allItems; track file) { | ||
<form [formGroup]="formGroup"> | ||
<sky-file-drop | ||
linkUploadHintText="Start with http:// or https://" | ||
formControlName="fileDrop" | ||
[acceptedTypes]="acceptedTypes" | ||
[allowLinks]="true" | ||
[hintText]="hintText" | ||
[helpPopoverContent]="inlineHelpContent" | ||
[labelText]="labelText" | ||
[maxFileSize]="maxFileSize" | ||
[stacked]="stacked" | ||
[validateFn]="validateFile" | ||
/> | ||
</form> | ||
|
||
@for (file of fileDrop.value; track file) { | ||
<sky-file-item [fileItem]="file" (deleteFile)="deleteFile($event)" /> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
<sky-file-drop | ||
hintText="Really long hint text that should wrap and be confined to below the file drop element. We set the text to have a small margin below the drop and link controls, and if there are any errors (shown below) there will be a slight spacing between this element and those errors." | ||
labelText="File attachment field" | ||
linkUploadHintText="Start with http:// or https://" | ||
helpKey="help.html" | ||
[acceptedTypes]="acceptedTypes" | ||
[allowLinks]="true" | ||
[maxFileSize]="maxFileSize" | ||
[minFileSize]="minFileSize" | ||
[required]="required" | ||
[validateFn]="validateFile" | ||
[stacked]="true" | ||
(filesChanged)="filesUpdated($event)" | ||
(linkChanged)="linkAdded($event)" | ||
/> | ||
@for (file of allItems; track file) { | ||
<sky-file-item [fileItem]="file" (deleteFile)="deleteFile($event)" | ||
><input type="text" | ||
/></sky-file-item> | ||
} | ||
|
||
<form [formGroup]="formGroup"> | ||
<sky-file-attachment | ||
<sky-file-drop | ||
hintText="Really long hint text that should wrap and be confined to below the file drop element. We set the text to have a small margin below the drop and link controls, and if there are any errors (shown below) there will be a slight spacing between this element and those errors." | ||
labelText="File attachment field" | ||
linkUploadHintText="Start with http:// or https://" | ||
helpKey="help.html" | ||
formControlName="attachment" | ||
helpPopoverContent="Sample help content" | ||
helpPopoverTitle="Inline help" | ||
hintText="Sample hint text" | ||
labelText="Single file attachment" | ||
required="true" | ||
[acceptedTypes]="acceptedTypes" | ||
[allowLinks]="true" | ||
[maxFileSize]="maxFileSize" | ||
[required]="required" | ||
[validateFn]="validateFile" | ||
(fileChange)="onFileChange($event)" | ||
[stacked]="true" | ||
/> | ||
</form> | ||
|
||
@for (file of attachment.value; track file) { | ||
<sky-file-item [fileItem]="file" (deleteFile)="deleteFile($event)" /> | ||
} | ||
|
||
Values | ||
<div>Touched: {{ attachment.touched }}</div> | ||
<div>Dirty: {{ attachment.dirty }}</div> | ||
<div>Value: {{ attachment.value | json }}</div> | ||
|
||
<button class="sky-btn sky-btn-primary" type="button" (click)="markTouched()"> | ||
mark touched | ||
</button> | ||
<button class="sky-btn sky-btn-primary" type="button" (click)="setFiles()"> | ||
set files | ||
</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,7 @@ | |
|
||
<sky-form-errors | ||
[id]="errorId" | ||
[errors]="ngControl?.errors ?? fileErrorValidation" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we handle all the errors inside |
||
[errors]="ngControl?.errors" | ||
[labelText]="labelText" | ||
[touched]="ngControl?.touched" | ||
[dirty]="ngControl?.dirty" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -594,8 +594,18 @@ export class SkyFileAttachmentComponent | |
} | ||
} | ||
|
||
#handleFiles(files?: FileList | null): void { | ||
if (files) { | ||
#handleFiles(fileList?: FileList | null): void { | ||
if (fileList) { | ||
const files: SkyFileItem[] = []; | ||
|
||
if ('item' in fileList) { | ||
for (let index = 0; index < fileList.length; index++) { | ||
files.push({ | ||
file: fileList.item(index), | ||
} as SkyFileItem); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the shared file validation function to take in |
||
|
||
const processedFiles = this.#fileAttachmentService.checkFiles( | ||
files, | ||
this.minFileSize, | ||
|
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.
You can avoid the constructor and just assign the variables immediately: