File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 66 EventEmitter ,
77 TemplateRef
88} from "@angular/core" ;
9- import { NG_VALUE_ACCESSOR } from "@angular/forms" ;
9+ import { ControlValueAccessor , NG_VALUE_ACCESSOR } from "@angular/forms" ;
1010
1111import { I18n } from "carbon-components-angular/i18n" ;
1212import { FileItem } from "./file-item.interface" ;
@@ -90,7 +90,7 @@ const noop = () => { };
9090 }
9191 ]
9292} )
93- export class FileUploader {
93+ export class FileUploader implements ControlValueAccessor {
9494 /**
9595 * Counter used to create unique ids for file-uploader components
9696 */
@@ -287,4 +287,15 @@ export class FileUploader {
287287 registerOnChange ( fn : any ) {
288288 this . onChangeCallback = fn ;
289289 }
290+
291+ /**
292+ * `ControlValueAccessor` method to programmatically disable the checkbox.
293+ *
294+ * ex: `this.formGroup.get("myFileUploader").disable();`
295+ *
296+ * @param isDisabled `true` to disable the file uploader
297+ */
298+ setDisabledState ( isDisabled : boolean ) {
299+ this . disabled = isDisabled ;
300+ }
290301}
Original file line number Diff line number Diff line change @@ -295,11 +295,29 @@ class NgModelFileUploaderStory {
295295 Upload
296296 </button>
297297 </form>
298+ <form [formGroup]="disabledFormGroup" (ngSubmit)="onUpload()">
299+ <ibm-file-uploader
300+ [title]="title"
301+ [description]="description"
302+ [buttonText]="buttonText"
303+ [buttonType]="buttonType"
304+ [accept]="accept"
305+ [multiple]="multiple"
306+ [skeleton]="skeleton"
307+ [size]="size"
308+ formControlName="files">
309+ </ibm-file-uploader>
310+ <div [id]="notificationId" style="width: 300px; margin-top: 20px"></div>
311+ <button ibmButton *ngIf="disabledFormGroup.get('files').value && disabledFormGroup.get('files').value.size > 0" type="submit">
312+ Upload
313+ </button>
314+ </form>
298315 `
299316} )
300317class ReactiveFormsStory implements OnInit {
301318 static notificationCount = 0 ;
302319 public formGroup : FormGroup ;
320+ public disabledFormGroup : FormGroup ;
303321
304322 @Input ( ) notificationId = `notification-${ FileUploaderStory . notificationCount } ` ;
305323 @Input ( ) title ;
@@ -325,6 +343,10 @@ class ReactiveFormsStory implements OnInit {
325343 this . formGroup = this . formBuilder . group ( {
326344 files : new FormControl ( new Set < any > ( ) , [ Validators . required ] )
327345 } ) ;
346+ this . disabledFormGroup = this . formBuilder . group ( {
347+ files : new FormControl ( new Set < any > ( ) , [ Validators . required ] )
348+ } ) ;
349+ this . disabledFormGroup . disable ( )
328350 }
329351
330352 onUpload ( ) {
You can’t perform that action at this time.
0 commit comments