Skip to content

Instantly share code, notes, and snippets.

@thetrickster
Last active December 16, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetrickster/5470271 to your computer and use it in GitHub Desktop.
Save thetrickster/5470271 to your computer and use it in GitHub Desktop.
On facebook Like button event, enable form.fb-like-form input elements
// Setup a variable to contain all the form input elements to enable
var myDisabledFields = "input, textarea, select, button";
// The FB.Event.subscribe method lets us run some javascript on certain events. The "Like" event for the Javascript SDK is "edge.create"
FB.Event.subscribe('edge.create',
// Once we're subscribed, anytime the Like button is cliked Facebook sends us back some data in an array.
// We'll call that data array "response".
function(response) {
// If you uncomment the next line, you'll see the data returned in your console
// console.log(response);
// Let's use some jQuery to target form with the class "fb-like-form" and find and enable
// each of the matching input elements we put in our variable above
jQuery(".fb-like-form").find(myDisabledFields).each(function() {
// Remove the "disabled" attribute for this element
jQuery(this).removeAttr("disabled");
// Optionally, do other stuff here.
});
}
);
// Let's re-enable the form when someone "UnLikes" a Like button
FB.Event.subscribe("edge.remove", function(response){
jQuery(".fb-like-form").find(myDisabledFields).each(function() {
jQuery(this).attr("disabled", "disabled");
});
});
@thetrickster
Copy link
Author

Place the code above after your FORM and Facebook Like Button markup and before the closing BODY tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment