Created
August 6, 2014 13:54
-
-
Save neokoenig/0112bf45d481283c8f9d to your computer and use it in GitHub Desktop.
Gridmanager save contents to hidden form field using external button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
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
Okay, not the best solution in my mind, but here is what I did to your code:
There may be a way to do it with the gm functions, but I was not able to find one, so I just decided to code it thus. Of course if tinymce changes how it names the inputs OR gridmanager changes the html comments and positioning with the gm divs, it will break the code.
On a page with one row starting on the page and after adding one, your original code pulled this:
<div class="row"><div class="column col-md-6 col-sm-6 col-xs-6"><p>New Content1</p></div><div class="column col-md-6 col-sm-6 col-xs-6"><p>New Content2</p></div></div><div class="row"><div class="column col-md-12 col-sm-12 col-xs-12"><p>New section 1</p></div></div><div class="row"><div class="col-sm-12 col-md-12 col-xs-12 column">Not Yet Published</div></div>
My code pulls this:
<div class="row"><div class="column col-md-12 col-sm-12 col-xs-12"><p>New Content</p></div></div><div class="row"><div class="col-sm-12 col-md-12 col-xs-12 column">Not Yet Published</div></div>