Files
wordpress-preseed/wp-content/plugins/advanced-custom-fields/assets/build/js/_acf-field-select.js
2019-09-11 19:08:46 +02:00

57 lines
1.0 KiB
JavaScript

(function($, undefined){
var Field = acf.Field.extend({
type: 'select',
select2: false,
wait: 'load',
events: {
'removeField': 'onRemove'
},
$input: function(){
return this.$('select');
},
initialize: function(){
// vars
var $select = this.$input();
// inherit data
this.inherit( $select );
// select2
if( this.get('ui') ) {
// populate ajax_data (allowing custom attribute to already exist)
var ajaxAction = this.get('ajax_action');
if( !ajaxAction ) {
ajaxAction = 'acf/fields/' + this.get('type') + '/query';
}
// select2
this.select2 = acf.newSelect2($select, {
field: this,
ajax: this.get('ajax'),
multiple: this.get('multiple'),
placeholder: this.get('placeholder'),
allowNull: this.get('allow_null'),
ajaxAction: ajaxAction,
});
}
},
onRemove: function(){
if( this.select2 ) {
this.select2.destroy();
}
}
});
acf.registerFieldType( Field );
})(jQuery);