Here I am trying to fill 'source' value with an ajax call, which will fill a dropdown on every click.
But it's not working. If anyone tried this earlier please let me know.
<link href="//
cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet" />
<script src="//
cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<script>
jQuery(document).ready(function() {
(function($) {
'use strict';
$(function() {
if ($('#editable-form').length) {
$.fn.editable.defaults.mode = 'inline';
$.fn.editableform.buttons =
'<button type="submit" class="btn btn-primary btn-sm editable-submit">' +
'<i class="fa fa-fw fa-check"></i>' +
'</button>' +
'<button type="button" class="btn btn-warning btn-sm editable-cancel">' +
'<i class="fa fa-fw fa-times"></i>' +
'</button>';
$("[id^='owner']").editable({
id_val : $("[id^='owner']").attr('id'),
loc : id_val.replace('owner', 'loc'),
loc_nam: document.getElementById(loc).value,
source: function (url, loc_nam){
$.ajax({
url: '/XXX/ajax/load_users',
data: {
'location': loc_nam
},
dataType: 'json',
success: function (data) {
var js_obj = JSON.parse(data.loc_users);
if(js_obj.length==0){
alert("No Users Available in system for selected location");
}
var usrdata = []
for (var i = 0; i < js_obj.length; i++) {
var pk = js_obj[i]['pk'];
var name = js_obj[i]['fields']['first_name']+" "+js_obj[i]['fields']['last_name'];
usrdata.push({value: pk, text: name})
}
console.log("==>>");
console.log(usrdata);
return usrdata;
},
});
}
});
};//END if ($('#editable-form').length)
});
});
Option 2:
jQuery(document).ready(function() {
//toggle `popup` / `inline` mode
$.fn.editable.defaults.mode = 'popup';
function getSource() {
var url = "/api/rpc/payments/status_options";
return $.ajax({
type: 'GET',
async: true,
url: url,
dataType: "json"
});
}
getSource().done(function(result) {
$('.payments-click').editable({
type: 'select',
title: 'Select status',
placement: 'right',
value: 2,
source: result
/*
//uncomment these lines to send data on server
,pk: 1
,url: '/post'
*/
});
}).fail(function() {
alert("Error with payment status function!")
});
});
--
Thanks & Regards!
Sujata S. Aghor