Merge pull request #21529 from ricardoasmarques/wip-fix-rbd-form

mgr/dashboard: Display RBD form errors on submission

Reviewed-by: Stephan Müller <smueller@suse.com>
Reviewed-by: Volker Theile <vtheile@suse.com>
This commit is contained in:
Lenz Grimmer 2018-04-26 11:44:20 +02:00 committed by GitHub
commit ed46117e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -301,7 +301,7 @@
</div>
<div class="panel-footer">
<div class="button-group text-right">
<cd-submit-button [form]="rbdForm"
<cd-submit-button [form]="formDir"
type="button"
(submitAction)="submit()">
<span i18n>{mode, select, editing {Update} cloning {Clone} copying {Copy} other {Create}}</span> RBD

View File

@ -1,7 +1,7 @@
<button [type]="type"
class="btn btn-sm btn-primary tc_submitButton"
[disabled]="loading"
(click)="submit()">
(click)="submit($event)">
<ng-content></ng-content>
<span *ngIf="loading">
<i class="fa fa-spinner fa-spin fa-fw"></i>

View File

@ -1,5 +1,5 @@
import { Component, ElementRef, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { AbstractControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms';
import * as _ from 'lodash';
@ -27,7 +27,7 @@ import * as _ from 'lodash';
styleUrls: ['./submit-button.component.scss']
})
export class SubmitButtonComponent implements OnInit {
@Input() form: FormGroup;
@Input() form: FormGroup | NgForm;
@Input() type = 'submit';
@Output() submitAction = new EventEmitter();
@ -40,14 +40,22 @@ export class SubmitButtonComponent implements OnInit {
if (_.has(this.form.errors, 'cdSubmitButton')) {
this.loading = false;
_.unset(this.form.errors, 'cdSubmitButton');
this.form.updateValueAndValidity();
// Handle Reactive forms.
if (this.form instanceof AbstractControl) {
(<AbstractControl>this.form).updateValueAndValidity();
}
}
});
}
submit() {
submit($event) {
this.focusButton();
// Special handling for Template driven forms.
if (this.form instanceof FormGroupDirective) {
(<FormGroupDirective>this.form).onSubmit($event);
}
if (this.form.invalid) {
this.focusInvalid();
return;