Grails

RemoteField with additional params sends 'this.value' as string to server instead of the fields value

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.0.2
  • Component/s: Ajax
  • Labels:
    None

Description

When having this remoteField tag:

<g:remoteField action="hello" id="1" params="[var1: 'one', var2: 'two']" update="success" name="myname" value="myvalue"/>

the expected html would be:

<input type="text" name="myname" value="myvalue" onkeyup="new Ajax.Updater('success','/test-yui/remoteTags/hello/1',{asynchronous:true,evalScripts:true,parameters:'var1=one&var2=two&value='+this.value});" />

but is:

<input type="text" name="myname" value="myvalue" onkeyup="new Ajax.Updater('success','/test-yui/remoteTags/hello/1',{asynchronous:true,evalScripts:true,parameters:'var1=one&var2=two&value=this.value'});" />

The problem is that this.value is included within the single quotes but should be outside. The result is that instead of the field's value 'this.value' is send as string to the server.

Activity

Hide
Marcel Overdijk added a comment -

I've a similar problem with remoteFunction tag if you use the params tag as map:

<select onchange="${remoteFunction(action:'hello',update:'success', params:[value: 'this.value'] )}">
<option value="1">first</option>
<option value="2">second</option>
</select>

If you use a String as params attr (like params:'\'value=\' + this.value') then it works.

Show
Marcel Overdijk added a comment - I've a similar problem with remoteFunction tag if you use the params tag as map: <select onchange="${remoteFunction(action:'hello',update:'success', params:[value: 'this.value'] )}"> <option value="1">first</option> <option value="2">second</option> </select> If you use a String as params attr (like params:'\'value=\' + this.value') then it works.
Hide
Juergen added a comment -

I have had the same issue in grails 1.1.1
the shown workaround still works fine.

heres a taglib function implementing this workaround, so that the syntax is like (i think) it should be

def remoteField= { attrs, body ->
def params = attrs['params']?:null
if(params){
String pString = "\'"
params.each { key, value ->
pString += "${key}=${value}&"
}
pString += "\'"
attrs['params'] = pString;
}
out << g.remoteField(attrs, body)
}

Show
Juergen added a comment - I have had the same issue in grails 1.1.1 the shown workaround still works fine. heres a taglib function implementing this workaround, so that the syntax is like (i think) it should be def remoteField= { attrs, body -> def params = attrs['params']?:null if(params){ String pString = "\'" params.each { key, value -> pString += "${key}=${value}&" } pString += "\'" attrs['params'] = pString; } out << g.remoteField(attrs, body) }
Hide
Alexander Zeillinger added a comment -

Unfortunately this is still broken in 1.3.5, the workaround of Juergen works fine though.
Please reopen and fix.

Show
Alexander Zeillinger added a comment - Unfortunately this is still broken in 1.3.5, the workaround of Juergen works fine though. Please reopen and fix.
Hide
Alexander Zeillinger added a comment -

Upon further investigation I found out that is bug only happens when using jQuery. The current implementation works fine with Prototype.

Using the above example with jQuery this is the generated HTML:

<input type="text" name="myname" value="myvalue" onkeyup="jQuery.ajax({type:'POST',data:{'var1': 'one','var2': 'two','value': '\'+this.value+\''}, url:'/project/test/hello/1',success:function(data,textStatus){jQuery('#success').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});" />

And the action receives the following params:

[value:'+this.value+', var1:one, var2:two, id:1, action:hello, controller:test]

Show
Alexander Zeillinger added a comment - Upon further investigation I found out that is bug only happens when using jQuery. The current implementation works fine with Prototype. Using the above example with jQuery this is the generated HTML: <input type="text" name="myname" value="myvalue" onkeyup="jQuery.ajax({type:'POST',data:{'var1': 'one','var2': 'two','value': '\'+this.value+\''}, url:'/project/test/hello/1',success:function(data,textStatus){jQuery('#success').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});" /> And the action receives the following params: [value:'+this.value+', var1:one, var2:two, id:1, action:hello, controller:test]
Hide
Peter Ledbrook added a comment -

That should be raised against the jQuery plugin.

Show
Peter Ledbrook added a comment - That should be raised against the jQuery plugin.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: