1

私は Jeditable と autocomplete を使用していますが、送信時に名前の代わりに ID を渡す必要があります。

次のコードを使用します。

var data = [ 
    { text: 'PC Service 1', id: '46' }, 
    { text: 'PC Service 2', id: '48' }, 
    { text: 'PC Service 3', id: '49' }, 
    { text: 'Serviciu 1', id: '47' } 
];

jQuery.editable.addInputType('autocomplete', {
    element: jQuery.editable.types.text.element,
    plugin: function(settings, original) {
        jQuery('input', this).autocomplete(data, {
            dataType: 'json',
            parse: function(data) {                                        
                return jQuery.map(data, function(item) {
                    return {
                        data:   item,
                        value:  item.id,
                        result: item.name
                    };
                });
            },
            formatItem: function(item) {    
                return item.text;
            }
        }).result(function(event, item) {
            console.log ("Item: "  + item.id);
            nameId = item.id;
        });
    }
});

jQuery(".editableFieldAutocomplete").editable("index.cgi?action=plugin", { 
    indicator: "<img src='/$instance/images/loaders/loader2.gif'>",
    tooltip:   "Editeaza",
    type:      "autocomplete",
    event:     "mouseover",
    style:     "inherit",
    id:        'fieldId',
    name:      'fieldValue',
    submitdata: function ( value, settings ) {
        var nameId = nameId;
        console.log ("nameId: "  + nameId);
        return {
            invoiceId: "$fact",
            mode: "api",
            sec: "updateInvoiceJeditable_fct",
            nameId: nameId
        };
    }, 
    style: 'display: inline',
    autocomplete: {
        minLength  : 2,
        data : [ 
            { label: "Aberdeen", value:"1"}, 
            { label: "Ada", value: "2"}, 
            { label: "Adamsville", value: "3"}, 
            { label: "Addyston", value: "3"}, 
            { label: "Adelphi", value: "3"}, 
            { label: "Adena", value: "3"}, 
            { label: "Adrian", value: "3"}, 
            { label: "Akron", value: "3"}
        ]
    }
});
4

0 に答える 0