pee2pee
pee2pee

Reputation: 3802

X-Editable: How to Add Parameters

My current (very very simple) script is as follows:

    <script type="text/javascript">
        $(document).ready(function () {
            $('.edit').editable();
        });
    </script>

My HTML is as follows:

<span class="edit editable editable-pre-wrapped editable-click" data-title="Target Value">£135,000</span>

My question is how do I add more parameters to this so the processing script picks them up? Let's say I wanted to add:

data-title="cows"

I have tried the following which doesn't work but changing $(this).data("data-title") to a number, it works. ANy idea?

<script type="text/javascript">
            $(document).ready(function () {
                $('.edit').editable({
                    type: 'textarea',
                    pk: 1,
                    url: '/poo',
                    ajaxOptions: {
                        type: 'POST'
                    },
                    params: {
                        titleDesc: $(this).data("data-title"),
                    }
                });
            });
        </script>

Upvotes: 1

Views: 1929

Answers (2)

user18642723
user18642723

Reputation: 1

// Additional params for submit. If defined as object - it is appended to original ajax data (pk, name and value). If defined as function - returned object overwrites original ajax data.

params: function(params) { params.a = 1; return params; }

Upvotes: -1

teck yap
teck yap

Reputation: 69

You may use the url method to achieve this.

    <a href="#" class="comments" data-type="textarea" data-siteid="123456789" data-commentdate="2018-12-31"></a>

    $('.comments').editable({
        title: 'Enter comments',
        placeholder: 'Enter comments',
        type: 'textarea',
        rows: 2,
        cols: 50,
        validate: function (value) {
            if ($.trim(value) == '') {
                return 'This field is required';
            }
        },
        ajaxOptions: {
            type: 'post'

        },
        url: function (params) {
            var comment = params.value;
            var elem = $(this);
            var siteId = elem.data('siteid');
            var commentDate = elem.data('commentdate');

            $.ajax({
                url: '/GlobalBudget/SaveComment',
                type: 'POST',
                data: {
                    siteId: siteId,
                    comment: comment,
                    commentDate: commentDate
                },
                success: function (response) {
                    if (response.success) {
                        toastr.success(response.message);
                    } else {
                        toastr.error(response.message);
                    }
                },
                error: function (response) {
                    toastr.error("Could not save your comment. Please try again later.");
                }
            });
        }
    });

Upvotes: 2

Related Questions