I'm trying to call a jquery function from a Grails .gsp page using g:link. Is this possible? Currently, I'm using a regular button (which is successful in calling $( "#opener" )
:
<li><button id="opener">Export</button></li>
But I am looking to use something like the following:
<div id="dialog" title="Export">
<p>This is a sample dialog...</p>
</div>
<li><g:link class="export">
<g:message code="default.new.label" args="[entityName]" />
</g:link></li>
Here is my function:
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<style>
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { text-align: center; float: none; }
</style>
<script>
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() {
$( "#dialog" ).dialog({
resizable: false,
autoOpen: false,
show: "blind",
hide: "explode",
buttons: {
"OK!": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});
</script>
I would appreciate any help. Thanks!
Last time I needed to do this (Grails 1.3), I ended up just using a standard HTML <a></a>
link with onclick
. For example:
<a href="#" class="export" onclick="some_function();"><g:message code="default.new.label" args="[entityName]" /></a>
There might be a way to do this with a Grails taglib now with 2.1.x, but if there I am unaware of it.