plugins - Add Cancel Button to a Custom Meta Box

admin2025-06-07  60

Any ideas how I could add a cancel button, like the default one in the Publish meta box, to a custom meta box?

The standard code is <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel">Cancel</a> I guess it's using some js to do the cancel/reset action so it's not easy to replicate.

I basically want to add a button that will clear an input field in my meta box. input type=reset will clear all the fields on the page, so I wanted to see if I could use WP's toolset.

Open to ideas for the best solution here.

Any ideas how I could add a cancel button, like the default one in the Publish meta box, to a custom meta box?

The standard code is <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel">Cancel</a> I guess it's using some js to do the cancel/reset action so it's not easy to replicate.

I basically want to add a button that will clear an input field in my meta box. input type=reset will clear all the fields on the page, so I wanted to see if I could use WP's toolset.

Open to ideas for the best solution here.

Share Improve this question asked Oct 20, 2018 at 17:05 SalSal 1535 bronze badges 2
  • Have you added a cancel button? Even if it's non-functional, I think you can ignore the whole metabox/WP thing and treat this as a pure "I have a series on input form elements inside of a div container, how do I clear them when a link is clicked?". If you're looking for a WP specific way to do this though, there isn't one – Tom J Nowell Commented Oct 20, 2018 at 17:31
  • Yeah, I was hoping for a Wordpress-specific way to do this. If there isn't something like that, then I can use a line of js to handle it. – Sal Commented Oct 20, 2018 at 19:38
Add a comment  | 

1 Answer 1

Reset to default 0

I ended up using this:

<a class="clear_button hide-if-no-js button-cancel" title="clear" data-clear style="text-decoration:underline;">Clear</a>

It does the job. I was hoping for something more "Wordpressy" but don't see a metabox cancel function.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749244909a317570.html

最新回复(0)