Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!>
Thanks for joining our community and helping improve Syncfusion products!
When set the timepicker hour dynamically based on some condition. the value does not update when using two-way binding
Sample code :
<div> First timepicker: <SfTimePicker <TimePickerEvents </SfTimePicker> </div> <div> Second timepicker: <SfTimePicker <TimePickerEvents </SfTimePicker> </div> @code private DateTime? now { get; set; } = DateTime.Now; private DateTime? secondNow { get; set; } = DateTime.Now.AddHours(1); private DateTime secondMin { get; set; } private DateTime timePickerMinimum = new private DateTime timePickerMaximum = new protected override void OnInitialized() { this.secondMin = System.Convert.ToDateTime(this.now); } public void OnFirstChange(Syncfusion.Blazor.Calendars.ChangeEventArgs<DateTime?> args) { if (args.Value == null) return; // now = (DateTime)args.Value; // Issue: Line below causes method OnSecondChange to go into endless loop if (secondNow < args.Value) { secondNow = System.Convert.ToDateTime(this.now).AddHours(1); } } public void OnSecondChange(Syncfusion.Blazor.Calendars.ChangeEventArgs<DateTime?> args) { if (args.Value == null) return; Console.WriteLine("Hello from OnSecondChange! " + secondNow.ToString()); if (args.Value < now) { secondNow = System.Convert.ToDateTime(this.now).AddHours(1); StateHasChanged(); } } } |
Replication procedure:
1. Run sample, notice values of two timepickers - second timepicker should be 1 hour ahead of first one.
2. Manually enter a time that is lower than the first timepicker into second timepicker, press ENTER.
3. Result: Value of second timepicker should remain one hour ahead of first timepicker.
4. Now, repeat step 2 (manually enter time that is lower than first timepicker into second timepicker), this time do not press ENTER - just click somewhere on page.
5. Result: Value has changed to what you entered although event handler code changed it. This is not desirable!