0

I have a form with a managed_file field where I need to know when the upload button is clicked, and then perform an action. I decide to make it by attaching a behavior to my button but it also trigger when I click on the remove button. Here is my code:

Drupal.behaviors.mattButtons = {
    attach: function (context) {
    jQuery('input.form-submit', context).bind('mousedown', Drupal.matt.checkFile );
    }
};


Drupal.matt = Drupal.matt || {
    checkFile : function(){
        console.log("Hello");
        var url = jQuery('.file a').attr('href');
        console.log(url);
    }
};

Is there any way to only attch my behvior on the file upload button?

1 Answer 1

0

You can simply be more specific with your jQuery selector. For example, you could theme_file_managed_file to give your upload button it's own class and then change your jQuery('input.form-submit', context) line to include that class in the selector.

jQuery('input.my-upload-class', context)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.