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

Checkbox state is inconsistent on mobile for "up" event #493

Open
sritchie opened this issue Dec 13, 2022 · 5 comments
Open

Checkbox state is inconsistent on mobile for "up" event #493

sritchie opened this issue Dec 13, 2022 · 5 comments

Comments

@sritchie
Copy link
Contributor

Like in #492, I've implemented the Euler curve demo with state stored external to the board. I'm attempting to use the "up" event on a checkbox to register when the state changes.

Here is the demo: https://jsxgraph.mentat.org/#what_is_jsxgraph?

I've found two issues:

  1. on Desktop (Brave, Safari), the instance that comes into the event handler for an "up" event does NOT yet have its state updated. If I use !arg.Value(), I can get the demo to work.
  2. On a mobile device (Brave on iOS), the state is not consistent at all, so clicking the checkbox multiple times will sometimes cause the board to get out of sync with the checkbox state.

Is this a bug? Or am I perhaps not using the correct event?

Thank you!

@alfredwassermann
Copy link
Member

So far, the "change" event is the only registered event. Would this be sufficient?

@sritchie
Copy link
Contributor Author

sritchie commented Dec 19, 2022

I think this would work well, but when I register for "change" the handler doesn't fire for me.

Here is a repro of what I was seeing, meant to run in the examples directory. This is using the current es6 branch on the Brave browser.

<html>
    <head>
        <title>Board events</title>
        <link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
        <script type="text/javascript" src="../distrib/jsxgraphcore.js"></script>
    </head>
    <body>
        <div id="jxgbox" class="jxgbox" style="width: 800px; height: 800px; float: left"></div>
        <script type="text/javascript">
            /* <![CDATA[ */
            var board = JXG.JSXGraph.initBoard("jxgbox", {
                boundingbox: [-1, 1, 1, -1],
                axis: true,
                grid: true
            });
            var check = board.create("checkbox", [0.5, 0.5, "Toggle"]);

            check.on("up", function () {
                console.log("on up: " + this.Value());
            });

            check.on("change", function () {
                console.log("on change: " + this.Value());
            });
            /* ]]> */
        </script>
    </body>
</html>

@alfredwassermann
Copy link
Member

alfredwassermann commented Dec 20, 2022

This is strange. Your example works for me in Firefox and Brave, see https://jsfiddle.net/do6f5ng2/ for 1.4.6 and https://jsfiddle.net/wdpufa98 for 1.5.0-rc1. It also works for me if I include JSXGraph with import

@sritchie
Copy link
Contributor Author

sritchie commented Dec 20, 2022

Huh, maybe it is an OS X problem? Here is what I see on Brave, Safari and Firefox on my machine. No change event, and the "up" event sends the checkbox with (what seems to me) a Value opposite to what it should be.

2022-12-20 06 44 47

@alfredwassermann
Copy link
Member

Sorry, my last answer was completely wrong. I did not distinguish the event handlers in your example.

  1. The up event sends the status of the checkbox before the value changes, because the status change is triggered by a click event and HTML has a certain time lag between up (better: mouseup) and click. This is necessary to be able to distinguish between click and double click. So, sending the opposite value is the intended behaviour.

  2. Sorry, on('change',...) is not implemented, I was wrong. You have to add your event listener to the HTML checkbox by yourself, like this:

var check = board.create('checkbox', [0, 4, 'Click me']),
   p = board.create('point', [1, 1]);

JXG.addEvent(check.rendNodeCheckbox, 'change', function() {
   console.log("on change: " + this.Value());
}, check);

See also the documentation at https://jsxgraph.org/docs/symbols/Checkbox.html.

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

No branches or pull requests

2 participants