NiBE
NiBE

Reputation: 927

Passing params in createlink tag using jQuery

I'm trying to do a very easy thing, but I'm stuck and I feel so stupid. Basically I have a text area defined like this:

<textarea id="comment" name="comment" class="form-control" rows="7"></textarea>

Then I have a createlink tag where I would like to pass in the params section the content of the textarea, so I did something like this:

<g:createLink controller="admin"
              action="book"
              id="${bookingInstance?.id}"
              params="jQuery('#comment').serialize()"/>

Of course it doesn't work. Can anybody give me some advices?

thanks a lot

nibe

UPDATE: the create link it's inside a html tag. Like this:

<a class="btn btn-primary btn-centered" onclick="getComment();" title="Press me" href=
<g:createLink
   controller="admin"
   action="bookAccepted"
   id="${bookingInstance?.id}"/>>
  Press me
 </a>

The getComment() function is defined like this:

function getComment() {
    window.location.href = $(this).attr('href') + '?' + $('#commet').serialize();
    return false;
}

As result I got this error message: Provided id of the wrong type for class com.Booking. Expected: class java.lang.Long, got class java.lang.String. Stacktrace follows:Message: Provided id of the wrong type for class com.Booking. Expected: class java.lang.Long, got class java.lang.String

Upvotes: 0

Views: 1767

Answers (2)

Joshua Moore
Joshua Moore

Reputation: 24776

Well you have to do this with jQuery. So something like this perhaps:

<g:link controller="admin" action="book" id="${bookingInstance?.id"} onclick="return function() { window.location.href=$(this).attr('href') + '?' + $('#comment').serialize(); return false;}">My link</g:link>

Upvotes: 1

Carleto
Carleto

Reputation: 951

Or you can try use JS like that. Works fine for me, of course, for ajax call.

function sendTextArea(comment) {
     var params = {"comment":comment, "id": ${bookingInstance?.id}};
     console.log(params);
     ${remoteFunction(controller: 'admin', action: 'book', params:'params', update:'div')}
}

Upvotes: 0

Related Questions