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

Event Attribute Callbacks - Fires Twice. #798

Open
89gsc opened this issue Jun 26, 2018 · 2 comments
Open

Event Attribute Callbacks - Fires Twice. #798

89gsc opened this issue Jun 26, 2018 · 2 comments

Comments

@89gsc
Copy link

89gsc commented Jun 26, 2018

I have a check box which I have registered a JS callback for in order to hide / show some fields, as you can see there are a couple console logs in there to help me debug.

The problem with this is that for each change in the checkbox so unchecking it or checking it this code fires twice. with some odd results. See below the code for what I am getting as a console output.

function overrideTermChecked (changed, collection, shortcode) {

        function attributeByName (name) {
            return _.find(
                collection,
                function (viewModel) {
                    return name === viewModel.model.get('attr');
                }
            );
        }

        var updatedVal    = changed.value,
            override_term = attributeByName('term'),
            override_msg  = attributeByName('content');

        console.log(typeof updatedVal);
        console.log(updatedVal);
        if (updatedVal) {
            console.log('Should Show');
            override_term.$el.show();
            override_msg.$el.show();
        } else {
            console.log('Should Hide');
            override_term.$el.hide();
            override_msg.$el.hide();
        }
    }

    wp.shortcake.hooks.addAction('glossary_tooltip.override', overrideTermChecked);

image

So I am not able to make the 2 text fields for term / content show they remain hidden all the time. Is this an issue with my implementation?

@akkatanp
Copy link

I too am facing the same issue. Any solution?

@89gsc
Copy link
Author

89gsc commented Sep 19, 2018

I never sound a solution to this problem. I changed how I handled this by not using events and did somthing else which wont work in most cases for other users. Sorry I couldn't be more help.

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