Toggle

Toggle

menashemenashe Posts: 202Questions: 46Answers: 2

I spent well over a day on this, with no progress.

TWO questions.

I have a toggle (using Kevin's plug-in) in an Editor window.

How do I center the text (On/Off) within the input element and how do I center the input element with the surrounding div?

More importantly, I assume that I am missing some small piece of required code--my Toggle works (it toggles :)) and it saves the correct value (1/null) to the database. If I re-open the Editor window, he correct value is populated.

If I restart the web application, even though the database table contains a 1, the toggle shows OFF

The plug-in is below.

Please help!

Answers

  • kthorngrenkthorngren Posts: 21,722Questions: 26Answers: 5,027
    edited February 25

    The text looks centered in this example from this thread.

    I assume that I am missing some small piece of required code

    Possibly but It's hard to say without seeing the problem. The example code doesn't have the Editor component but is based on the Editor checkbox example. You may need to add the Editor portions of the code.

    For help debugging the styling and toggle syncing issues please provide a link to a test case replicating these issues.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • menashemenashe Posts: 202Questions: 46Answers: 2

    Kevin,

    Thanks anyway. I figured it out. (I shudder at the thought of having to include Editor code in a test case; I've tried but had no success in running it.)

    Somehow, in my mind, I had already narrowed it down to the plug-in code. So... I stared intently at the code until I realized that the get and set return... BOOLEAN!

    So, I modified my Editor PHP getFormatter from

            Field::inst('packaging_details.do_not_repurchase')
                ->getFormatter(function ($val, $data) {
                    return !$val ? 0 : 1;
                })
                ->setFormatter(function ($val, $data, $opts) {
                    return !$val ? null : 1;
                }),
    

    to

            Field::inst('packaging_details.do_not_repurchase')
                ->getFormatter(function ($val, $data) {
                    return !$val ? false : true;
                })
                ->setFormatter(function ($val, $data, $opts) {
                    return !$val ? null : 1;
                }),
    

    and all is copacetic!

Sign In or Register to comment.