Send custom parameter in x-editable
Asked Answered
S

1

7

I am using x-editable to populate select list in popup. Now I want to send my key to server, my code is something like that

<a href="#" id="status" data-type="select" data-pk="1" data-url="${g.createLink(controller: 'someController', action: 'someAction')}" data-title="Select CV" class="btn btn-primary">
    <image src="${resource(dir: 'images/template', file: 'logo11.png')}"/> ${session.someList?.size()} CV(s) Created
</a>
<script>
    $(function () {
        $('#status').editable({
            value: 1,
            source: [
                <g:each in="${session.someList}" var="xyz"   status="idx">
                    {value: ${xyz?.id}, text: "${xyz.title}",        srsSelected:                    ${xyz.id}, updateXyz: "updateXyz"},
                </g:each>
            ]
        });
    });
</script>

I want to send my srsSelected key to server, I did google but not getting the point...

Edit:

Now I am able to send my key to server(after long research) using

params: function (params) {  //params already contain `name`, `value` and `pk`
    var data = {};
    data['cvSelected'] = params.pk;
    return data;
}

therefore my updated code is:

<a href="#" id="status" data-type="select" data-pk="1" data-url="${g.createLink(controller: 'someController', action: 'someAction')}" data-title="Select CV" class="btn btn-primary">
    <image src="${resource(dir: 'images/template', file: 'logo11.png')}"/>
                ${session.someList?.size()} CV(s) Created
</a>
<script>
    $(function () {
        $('#status').editable({
            value: 1,
            source: [
                <g:each in="${session.someList}" var="xyz"   status="idx">
                    {value: ${xyz?.id}, text: "${xyz.title}", srsSelected:     ${xyz.id}, updateXyz: "updateXyz"},
                </g:each>
            ],
            params: function (params) {  //params already contain `name`, `value` and `pk`
                var data = {};
                data['srsSelected'] = params.pk;
                return data;
            }
        });
    });
</script>

I am able to send value of pk in srsSelected key but this time I need to set value of srsSelected dynamically.

Suckle answered 15/10, 2013 at 5:24 Comment(0)
S
13

And Now I found the method to set the value of srsSelected dynamically as

params: function (params) {
    params.srsSelected = params.pk            
    return params;
} 

and setting the value of data-pk attribute in anchor tag dynamic, we can get srsSelected at controller action.

Suckle answered 7/11, 2013 at 17:43 Comment(1)
Worked for me by using jQuery to get the parameter I wanted like : param.param_name : $(this).attr('data-param'); where 'data-param' is the inline value that I wanted.Leeway

© 2022 - 2024 — McMap. All rights reserved.