Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created August 6, 2014 13:54
Show Gist options
  • Save neokoenig/0112bf45d481283c8f9d to your computer and use it in GitHub Desktop.
Save neokoenig/0112bf45d481283c8f9d to your computer and use it in GitHub Desktop.
Gridmanager save contents to hidden form field using external button
<!-- The Gridmanager canvas -->
<div id="mycanvas" class="clearfix"></div>
<!-- The Form-->
<form method="post" action="saveme" id="gridmanager-save">
<!-- hidden Field-->
<input type="hidden" name="mycontent" id="mycontent" />
<input type="submit" name="submit" class="submit" />
</form>
</div>
<!--================== JS ================-->
<script>
$(document).ready(function(){
var gm = jQuery("#mycanvas").gridmanager().data('gridmanager');
$(".submit").on("click", function(e){
canvas = gm.$el.find("#" + gm.options.canvasId);
gm.deinitCanvas();
$("#mycontent").val(canvas.html());
$(this).submit();
});
});
</script>
</body>
</html>
@ddegil
Copy link

ddegil commented Feb 2, 2016

I came upon a better method to do the above.
In my save function I get the gridmaster data this way now:

                // We need the canvas in edit more
                if ($('.gm-edit-mode.btn-danger').length == 0)
                    $('.gm-edit-mode').trigger('click');
                // now grab the content (use .html or .text) and store it where I can get it after the post.
                $('#mycontent').val($('#mycanvas').find('textarea').html().trim());
                // Get out of edit mode now (so the user does not see the source before the post)
                $('.gm-edit-mode').trigger('click');

That is far easier than my previous post. :)

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