Question

I'm trying to implement a "publish" button from a custom post type metabox. Everything actually works fine if I either create a new button and manually call submit() or duplicate the regular submit buttons, except for one thing: if i change the title of the post, I always get the "Confirm Navigation" popup asking me if I want tstay or leave the page. It doesn't do this when using the regular "Update" button though, so there's gotta be a way to stop it, I just can't seem to get a handle on it.

Custom save button using a link:

<a href="#" id="saveChangesButton" class="button-primary alignright">Save</a>

// in ready()
$('#saveChangesButton').live('click', function() {
        $('#saveChangesButton').addClass('button-primary-disabled');
        $('#post').submit();
        return false;           
});

Custom save buttons trying to mimic the submitdiv's buttons:

<?php if ($_GET['action'] == 'edit') : ?>
    <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Save') ?>" />
    <input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="Update">

<?php else: ?>
    <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" />

    <input name="publish" type="submit" id="publish" class="button-primary" value="Publish" tabindex="5" accesskey="p">
<?php endif; ?>
Was it helpful?

Solution

You can stimulate click to Update post button like this.. Adding submit or update button to custom metabox?

<script>
jQuery('.metabox_submit').click(function(e) {
    e.preventDefault();
    jQuery('#publish').click();
});
</script>
<input type="submit" class="metabox_submit" value="Submit" />

OTHER TIPS

You can add a custom publish button by using jquery.

   <div class = "splw-mbf-banner"></div>  
        
          jQuery('.splw-mbf-banner').append('<input name="publish" type="submit" id="publish" class="publish-button" value="Publish" tabindex="5" accesskey="p">');

Also, hide the default publish button by using a simple jQuery code...

$('#submitdiv:has(#publish)').css({'display':'none'});
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top