RST
RST

Reputation: 602

Grails remoteFunction AJAX function in a GSP, accessing variable to use for params

I am wanting to dynamically set the params in a remoteFunction within a check box. I have tried lots of different combinations I'll show a couple below but I just recieve error like below...

so it basically my theory, in the scope of this method doesn't have a clue what an eventInstance is

In FireBug error console I receive ReferenceError: eventInstance is not defined

Test Combination 1
<g:checkBox name='completed' value="${eventInstance.completed}"
    onclick="${remoteFunction(action:'update', id:eventInstance.id, params:'\'id=\' + eventInstance.id+\'&version=\' + eventInstance.version' , onComplete: "tester()" )}" />


Test Combination 2 
<g:checkBox name='completed' value="${eventInstance.completed}" evt="${eventInstance}"
    onclick="${remoteFunction(action:'update', id:eventInstance.id, params:"[version=evt.version, editType='occurrence', title=evt.title, startTime=start, endTime=end, isRecurring=evt.isRecurring, completed='true']", onComplete: "tester()" )}" /> 

This works if manually entering i.e. hard-coding the data in but this is no use. Something silly which I just can't find the answer to :(

Upvotes: 0

Views: 5846

Answers (3)

sanghavi7
sanghavi7

Reputation: 754

this can help you,

    onchange="$
    {
         remoteFunction(asynchronous: false, 
              controller: 'mycontroller', 
              action: 'remoteMethod', 
              params: '\'p1='+params?.p1+'&p2=less&p3=\'+ this.value', update: 'remoteDiv')}" 

just try this one.

Upvotes: 0

sanghavi7
sanghavi7

Reputation: 754

this can help you,

onchange="${remoteFunction(asynchronous: false, controller: 'mycontroller', action: 'remoteMethod', params: '\'p1='+params?.p1+'&p2=less&p3=\'+ this.value', update: 'remoteDiv')}" 

just try this one.

Upvotes: 1

RST
RST

Reputation: 602

OK for this to work ... seems somewhat strange, you CAN NOT use grails variables i.e. sent from controller to use in GSP

Instead ... you HAVE TO save the variables into a JavaScript variable.

So for each of the variables I wanted to use from the eventInstance to use in the params i.e. id, version, any other fields contained within I simply did the following:

<script type="text/javascript">
    function tester() {
        $('#calendar').fullCalendar('refetchEvents');
    }

    var test0 = ${eventInstance.id};
    var test1 = ${eventInstance.version};
    var test3 ='${eventInstance.title}';
    var test4 = '${start}';
    var test5 = '${end}';
    var test6 = ${eventInstance.isRecurring};
    alert(test0 + test1 + test3 + test4 + test5 + test5 + 
</script>

then referenced these variables in the params section of the remoteFunction like follows:

<g:checkBox name='completed' value="${eventInstance.completed}"
onclick="${remoteFunction(action:'update', id:eventInstance.id, params:'\'id=\' + test0+\'&version=\' + test1+\'&editType=\'+"occurrence"', onComplete: "tester()" )}" />

Not sure if this is some kind of bug or simply something wrong in my approach, however I have tried every single combination possible and seems the only work around solution I could come up with

Upvotes: 1

Related Questions