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

time-picker value is not updated inside Reactive Form Control #43

Closed
Robinson-777 opened this issue Jan 23, 2018 · 6 comments
Closed

time-picker value is not updated inside Reactive Form Control #43

Robinson-777 opened this issue Jan 23, 2018 · 6 comments

Comments

@Robinson-777
Copy link

I used time-picker inside Reactive form control ,Issue I faced after changing the time picker view value not updated in component

@torabian
Copy link
Member

Can you provide us a little bit of more details, provide code that we can reproduce.

@bam-dreymers
Copy link
Contributor

bam-dreymers commented Jan 29, 2018

[Updated]

I added a new pull request to fix this - all changes are in the AtpDirective file:
https://github.com/owsolutions/amazing-time-picker/pull/51/files

I read this blog and basically just applied it to the directive: https://blog.angularindepth.com/never-again-be-confused-when-implementing-controlvalueaccessor-in-angular-forms-93b9eee9ee83

@shanthece
Copy link

having same issue in reactive forms, even after followed bam-dreymers answers

@torabian
Copy link
Member

I have merged the code since all builds are passing and there is no backward compatibility issue.
This will be available after 1.5.0 version, probably by 03 of March, when we deploy to npm.

Please open a new issue, if you still having problems for this.

@Beni90
Copy link

Beni90 commented Mar 29, 2018

Hi guys, just installed the time-picker and have this problem as well. Formfield value is not updated in the component.

When is this going to be fixed?

@ugiordan
Copy link

ugiordan commented Jul 12, 2018

@Beni90 you have two options to make it works:

  1. Applying the "atp-time-picker" directive to the input field, e.g.:
<label for="time_picker" class="control-label">Time Picker</label>
<input id="time_picker" formControlName="time_picker" type="time" atp-time-picker>
  1. Setting the value of the corresponding form control. This is my case, where I had and input group (input field + button) and want to make both the input and the button opening the time-picker
@Component({
  selector: 'form-time-picker',
  styleUrls: ['./form-time-picker.component.scss'],
  template: `
    <ng-container [formGroup]="formGroup">
     <label for="time_picker" class="control-label">Time Picker</label>
     <div class="input-group mb-2" id="time_picker" (click)="open()">
        <input id="time_picker"
               formControlName="time_picker"
               type="time"
               value="{{selectedTime}}"/>
        <div class="input-group-append">
          <button type="button" class="btn btn-primary btn-icon input-group-text">
            <i class="ion-ios-time-outline"></i>
          </button>
        </div>
      </div>
    </ng-container>
  `,
})
export class FormTimePickerComponent {
  @Input()
  formGroup: FormGroup;

  @Input()
  config: TimePickerConfig;

  selectedTime: string;

  constructor(private atp: AmazingTimePickerService) {
  }

  open() {
    const timePicker = this.atp.open(this.config.pickerConfig);

    timePicker.afterClose().subscribe(time => {
      this.selectedTime = time;
      this.formGroup.controls[this.config.name].setValue(time);
    });
  }

}

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

No branches or pull requests

6 participants