Reputation: 64
I'm trying to change a x-editable source data just before it is shown so that my dropdown menu entries are always fresh even if source changes.
Here is a link to explain: http://jsfiddle.net/XN7np/3/
// my source that can change over time
var source = [{'value': 1, 'text': 'fine'}, {'value': 2, 'text': 'bad'}];
$('#my_select').editable({
'mode' : 'inline',
'source': source,
});
$('#my_select').on('shown', function(ev, editable) {
// now changing my source just before dropdown is shown
source = [{'value': 1, 'text': 'GOOD'}, {'value': 2, 'text': 'FU'}];
//$(editable).editable('option', 'source', source); NOT WORKING
//$('#my_select').editable('option', 'source', source); NOT WORKING
//$(this).editable('option', 'source', source); NOT WORKING
});
any idea?
Upvotes: 3
Views: 15160
Reputation: 410
<td>
<a href="" class="update_record" data-name="status" id="status" data-type="select" data-pk="{{ $tracker->id }}" data-title="Enter status">{{ $tracker->statname }}</a>
</td>
<td> <a href="" class="update_record" data-name="category" id="category" data-type="select" data-pk="{{$tracker->id}}" data-title="Enter category">{{ $tracker->catname }}</a></td>
<script type="text/javascript">
$.fn.editable.defaults.mode = 'inline';
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': '{{csrf_token()}}'
}
});
var statusls = [{'value': 1, 'text': 'Initiated'}, {'value': 2, 'text': 'Interested'}, {'value': 3, 'text': 'Not interested'}, {'value': 4, 'text': 'Details Shared'}, {'value': 5, 'text': 'Negotiating'}, {'value': 6, 'text': 'Onboarded'}, {'value': 7, 'text': 'Being Verified'}, {'value': 8, 'text': 'Picking Up'}, {'value': 9, 'text': 'Live'}, {'value': 10, 'text': 'Dead'}, {'value': 11, 'text': 'Other'}, {'value': 12, 'text': 'Unverified'}, {'value': 13, 'text': 'InProcess'}];
var categoryls = [{'value': 1, 'text': 'Co Shared Offices'}, {'value': 2, 'text': 'Office Space'}, {'value': 3, 'text': 'Event Space'}, {'value': 4, 'text': 'Warehouse'}, {'value': 5, 'text': 'Destination'}, {'value': 6, 'text': 'Agricultural Plot'}, {'value': 7, 'text': 'Classroom | Tution | School'}, {'value': 8, 'text': 'Popup shop'}, {'value': 9, 'text': 'Factory'}, {'value': 10, 'text': 'Agricultural Land'}, {'value': 11, 'text': 'Empty Plot | Ground'}, {'value': 12, 'text': 'Live Streaming'}];
var verify_status = [{'value': 1, 'text': 'Unverified'}, {'value': 2, 'text': 'Inprocess'}, {'value': 3, 'text': 'Verified'}, {'value': 4, 'text': 'Issues'}];
$('.update_record').editable({
url: "{{ route('SupplyTrackerupdate') }}",
type: 'text',
'source': function() {
if ($(this).data('name') ==='status') {
return statusls;
}
if ($(this).data('name') == 'verification_status') {
return verify_status;
}
if ($(this).data('name') === 'category') {
return categoryls;
}
},
name: 'firstname',
pk: 1,
title: 'Enter Field'
});
</script>
Upvotes: 0
Reputation: 1
<span class="editable ea-appsch-agntid" data-type="select" data-source="URL" data-value="">agntname</span>
Upvotes: 0
Reputation: 164
This line works:
$('#my_select').editable('option', 'source', source);
You have to use double quote for "value" and "text", instead of single quote 'value', 'text' for any xeditable source, like source2:
var source2 = [{"value": 1, "text": "fine111"}, {"value": 2, "text": "bad22"}];
$('#change').click(function(e) {
$('#my_select').editable('option', 'source', source2)
});
copy above code to your fiddle example and see how it works.
Upvotes: 0
Reputation: 1414
I do not see it in the documentation, but you can pass a function to the source parameter like this:
var source = [{'value': 1, 'text': 'fine'}, {'value': 2, 'text': 'bad'}];
$('#my_select').editable({
'mode' : 'inline',
'source': function() {
return source;
},
});
This way it always uses the updated source array. I updated your fiddle: http://jsfiddle.net/XN7np/4/
Upvotes: 9