@androunie wrote:
Hello dear Ionic friends
I am making a form, this form contains text (name, age…) and one image.
Right now I can make sure the text are necessary by using a FormGroup but I would like to make sure that the form is valid ONLY IF the image is entered.So I tried this way: (HTML file)
<input formControlName="photo" type="file" (click)="selectImage()">
TS FILE:
ngOnInit() { this.sellingSneakForm = new FormGroup({ photo: new FormControl('', [Validators.required]), }); } selectImage() { let actionSheet = this.actionSheetCtrl.create({ title: 'Add an image', buttons: [ { text: 'Take a picture from camera', role: 'CAMERA', handler: () => { this.takePicture(); } }, { text: 'Choose from your gallery', role: 'GALLERY', handler: () => { this.selectPicture(); } }, { text: 'Cancel', role: 'cancel', handler: () => { } } ] }); actionSheet.present(); } takePicture() { this.camera.getPicture({ quality : 95, destinationType : this.camera.DestinationType.DATA_URL, sourceType : this.camera.PictureSourceType.CAMERA, encodingType: this.camera.EncodingType.JPEG, targetWidth: 500, targetHeight: 500, }).then(imageData => { this.base64Image = "data:image/jpeg;base64," + imageData; // imageData is a base64 encoded string this.Picture = imageData; //this.Picture is passing the string to our DB }, error => { console.log("ERROR -> " + JSON.stringify(error)); }); }
It is working 100% when I upload the image but my app does not need the image to push the item to the database… What I would like with this FormGroup and FormControl.
Is it possible this way ?
Thanks
Posts: 1
Participants: 1