Skip to content
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

nb-datepicker reactive form validation issue #1182

Closed
1 task
maihannijat opened this issue Jan 23, 2019 · 0 comments · Fixed by #1247
Closed
1 task

nb-datepicker reactive form validation issue #1182

maihannijat opened this issue Jan 23, 2019 · 0 comments · Fixed by #1247

Comments

@maihannijat
Copy link
Contributor

Issue type

I'm submitting a ... (check one with "x")

  • [ x] bug report
  • feature request

Issue description

Current behavior:

Using Input with [nbDatepicker]="datePicker" and Reactive Form. The validation rule is not defined and there is no required keyword in the template but leaving the input field empty makes the form invalid. The form is valid if date is entered.

Expected behavior:

A form with input empty (null) should be valid if it's not required and there is no validation rule.

Steps to reproduce:

1- Create Reactive Form with input having date picker.

Related code:

<nb-card>
	<nb-card-header>Fill the form</nb-card-header>
	<nb-card-body>

		<form [formGroup]="form" (ngSubmit)="submit()" aria-labelledby="title">

			<input nbInput
                   fullWidth
                   [nbDatepicker]="datePicker"
                   placeholder="Date"
                   formControlName="dateCtrl">
      <nb-datepicker #datePicker></nb-datepicker>

        <button nbButton
                    [disabled]="!form.valid">
              Submit
        </button>
    </form>
  </nb-card-body>
</nb-card>
export class AppComponent implements OnInit  {

  form;

  constructor(private fb: FormBuilder) {

  }

  submit() {
    alert('Valid Form');
  }

  ngOnInit() {
      this.form = this.fb.group({
      dateCtrl: [''],
    });
  }
}

StackBlitz StackBlitz Project

Note: Leave the field empty and click submit which is not clickable and then enter 2019-05-05 and you will see alert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants