由于Safari存在问题,因此将select2更新为版本4+;如果用户的选项不存在,我无法创建允许用户创建新条目。
我正在使用带有x-editable的Laravel。使用下面的代码,我可以选择选项但不能创建新选项。如果我将标签设置为true,我也无法获得选项。以前使用CreateSearchChoice对旧的Select2进行了处理。
HTML:
<td><a href='#' id='entryname' data-type="select2" data-disabled='{{ $catering_locked }}' data-value='{{ $theentrynameval }}' data-pk='{{ $catering_rows->id }}' data-url='{{ url('catering/updatedata') }}' class='entryname editable editable-click'>{{ $theentryname }}</a></td>
PHP:
$('.entryname').editable({
source: source: [{id:2104,text:"Tracey Forbes"},{id:2105,text:"Michelle Ridley"},{id:2106,text:"Lucy Dyke"},{id:3087,text:"Anthony Moore"},{id:3089,text:"Simon Jackson"},{id:3091,text:"Andy Putman"},{id:3095,text:"Stuart Anderson"},{id:3096,text:"Paul Simpson"},{id:3099,text:"Kyle Anderson"},{id:3101,text:"Stuart Bavridge"},{id:3103,text:"Mark Palmer"},{id:3105,text:"Chandler Hughes"},{id:3107,text:"Richard Boyd"},{id:3108,text:"Tony McQueen"},{id:3195,text:"Dave Robson"},{id:3197,text:"John Green"},{id:3198,text:"Jack Nesbit"},{id:3199,text:"Steven Nesbit"},{id:4168,text:"Jack Donoghue"},{id:5261,text:"Graham Anderson"}],
placement: 'right',
select2: {
placeholder: "Select Individual or Type New",
createTag: function (params) {
return {
id: params.term,
text: params.term,
newOption: true
}
},
templateResult: function (data) {
var $result = $("<span></span>");
$result.text(data.text);
if (data.newOption) {
$result.append(" <em>(new)</em>");
}
return $result;
}
},
success: function (e) {
$.gritter.add({
title: 'Success',
text: 'Data Edited Succesfully',
class_name: 'success'
});
},
error: function (e) {
$.gritter.add({
title: 'Error',
text: 'There was a problem making the changes',
class_name: 'danger'
});
}
});