question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DatePicker: onchange event called twice using touchUI="true"

See original GitHub issue

Describe the bug

When editing a cell with a datepicker in it, currentCell property returns null only on an iPhone This is due to on onchange event being called twice and resetting currentCell to null

This can also be reproduced on Safari (Mac/Desktop) Developer Tools by impersonating iPhone actual iPhone is not necessary.

Reproducer

See https://github.com/lprimak/apps/blob/f3afa201abe1250d543cdbe6ab2faaeb17566fa1/emailmanager/hope-website/testdatefield.xhtml#L37

Workaround:

onchange="var bt = PF('birthdayTable');
                    if (bt.currentCell) bt.saveCell(bt.currentCell)"

Expected behavior

onchange event would be called only once or currentCell would be non-null the second time on both iPhone and other browsers

PrimeFaces edition

Community

PrimeFaces version

12.0.0RC3, 12.0.0

Theme

Default

JSF implementation

Mojarra

JSF version

2.3

Java version

8 through 19

Browser(s)

Safari on iPhone

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:26 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
mellowarecommented, Oct 19, 2022

I have narrowed the bug down to this. When it switched from regular to touchUI mode the click events get registered twice.

updateResponsiveness: function() {
            if (this.options.autoDetectDisplay && this.options.responsiveBreakpoint && !this.options.inline) {
                var currentUI = this.options.touchUI;
                var newUi = PrimeFaces.env.mobile || PrimeFaces.env.isScreenSizeLessThan(this.options.responsiveBreakpoint);
                if (currentUI !== newUi) {
                    this.options.touchUI = newUi;
                    this._render();
                }
            }
        },

if I comment out this line they are only registered once but the wrong thing is happening.

 this._render();

So even though I am calling off before rebinding events the delegated click is still being registered.

 this.panel.off('click.datePicker-date', dateSelector).on('click.datePicker-date', dateSelector, null, function (event) {
1reaction
mellowarecommented, Oct 19, 2022

I fixed the NULL check in saveCell but still haven’t found a solution for the double mapping of click events.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery change event being fired twice - Stack Overflow
Problem is my bootstrap datepicker change event fire two times. The trick is to use changeDate instead of change.
Read more >
datepicker change event fired twice. #1233 - GitHub
In repo vizjerai/bootstrap-datepicker. This issue is fixed like this. Fix multiple calls to change #4 commit How is going at this repo?
Read more >
OnChange called twice | Telerik Forums
The request calls SingleUpdate action method where I use Reflection, the propertyName and the new value to update a value in my business...
Read more >
Why Type Ahead Text Control logs onChange Event twice if ...
I'm using Type Ahead Text Control from IBM BPM UI toolkit ; I notice it logs onChange Event twice if an item is...
Read more >
Solved: Onchange event often triggers when screen becomes
Solved: Greetings PowerAppers, I have a date picker control on an edit form in an app I am finishing up. The form and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found