我如何隐藏我的弹出窗口小部件实体参考视图小部件中的选定项目?
How i can hidden the selected items in my popup widget entity reference view widget?
起初她工作得很好,但我添加了一个 javascript 功能:当我取消选中项目时她将被删除,问题是:
当我添加项目时,所有项目总是显示在我的弹出窗口小部件中,我如何删除现有项目或其他表明项目已被选中的解决方案?
打印在屏幕和 js 代码下方:
(function($) {
Drupal.behaviors.entityreferenceViewWidget = {
attach: function(context, settings) {
var checkboxes = '#modal-content input.entity-reference-view-widget-select';
var selectAllSelector = '#entityreference-view-widget-select-all';
$(selectAllSelector).unbind('click').data('unselect', 0).click(function() {
if ($(this).data('unselect')) {
$(checkboxes).removeAttr('checked');
$(this).data('unselect', 0).text(Drupal.t('Select all'));
}
else {
$(checkboxes).attr('checked', 'checked');
$(this).data('unselect', 1).text(Drupal.t('Unselect all'));
}
return false;
});
if (settings.entityReferenceViewWidget) {
var ervwSetttings = settings.entityReferenceViewWidget.settings;
if (ervwSetttings.cardinality != -1 || $(checkboxes).length === 0) {
$(selectAllSelector).remove();
}
var selector = '#' + ervwSetttings.table_id + ' input[type=checkbox]:checked';
var selected_ids = '';
$(selector).each(function() {
selected_ids += $(this).val() + ';';
});
if (selected_ids.length > 0) {
$('input[name="selected_entity_ids"]').val(selected_ids.substring(0, selected_ids.length - 1)).trigger('change');
}
// We need to pass the settings via an hidden field because Views doesn't
// allow us to pass data between ajax requests.
if (settings.entityReferenceViewWidget.serialized) {
$('input[name="ervw_settings"]').val(settings.entityReferenceViewWidget.serialized);
}
}
$('.field-widget-entityreference-view-widget input[type=checkbox]:checked').each(function() {
$(this).onclick = function() {
console.log(1)
}
$(this).addClass('uncheck-to-remove').attr('title',Drupal.t('Uncheck to remove this item')).click(function() {
$(this).closest('tr').hide(500);
});
});
}
// }
};
// Create a new ajax command, ervw_draggable that is called to make the rows
// of the widget draggable.
Drupal.ajax.prototype.commands.ervw_draggable = function(ajax, response, status) {
$('#' + response.selector + ' tr').each(function(){
var el = $(this);
Drupal.tableDrag[response.selector].makeDraggable(el.get(0));
el.find('td:last').addClass('tabledrag-hide');
if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
el.find('.tabledrag-handle').hide();
}
else {
el.find('td:last').hide();
}
});
};
})(jQuery);
你不需要为此编写任何代码(隐藏部分必须用 js 代码 atm 编写),这只是配置。
要不显示在您创建的视图中填充的模态中已经选择的项目,您必须在节点的 nid 上有一个上下文过滤器。编辑此上下文过滤器并选中 "More" 菜单下的 "Exclude"(在添加多个值旁边)。
查看此视频:http://codekarate.com/daily-dose-of-drupal/entity-reference-view-widget 在 8:00 标记处。该视频几乎解释了此小部件的所有基本配置。
起初她工作得很好,但我添加了一个 javascript 功能:当我取消选中项目时她将被删除,问题是: 当我添加项目时,所有项目总是显示在我的弹出窗口小部件中,我如何删除现有项目或其他表明项目已被选中的解决方案? 打印在屏幕和 js 代码下方:
(function($) {
Drupal.behaviors.entityreferenceViewWidget = {
attach: function(context, settings) {
var checkboxes = '#modal-content input.entity-reference-view-widget-select';
var selectAllSelector = '#entityreference-view-widget-select-all';
$(selectAllSelector).unbind('click').data('unselect', 0).click(function() {
if ($(this).data('unselect')) {
$(checkboxes).removeAttr('checked');
$(this).data('unselect', 0).text(Drupal.t('Select all'));
}
else {
$(checkboxes).attr('checked', 'checked');
$(this).data('unselect', 1).text(Drupal.t('Unselect all'));
}
return false;
});
if (settings.entityReferenceViewWidget) {
var ervwSetttings = settings.entityReferenceViewWidget.settings;
if (ervwSetttings.cardinality != -1 || $(checkboxes).length === 0) {
$(selectAllSelector).remove();
}
var selector = '#' + ervwSetttings.table_id + ' input[type=checkbox]:checked';
var selected_ids = '';
$(selector).each(function() {
selected_ids += $(this).val() + ';';
});
if (selected_ids.length > 0) {
$('input[name="selected_entity_ids"]').val(selected_ids.substring(0, selected_ids.length - 1)).trigger('change');
}
// We need to pass the settings via an hidden field because Views doesn't
// allow us to pass data between ajax requests.
if (settings.entityReferenceViewWidget.serialized) {
$('input[name="ervw_settings"]').val(settings.entityReferenceViewWidget.serialized);
}
}
$('.field-widget-entityreference-view-widget input[type=checkbox]:checked').each(function() {
$(this).onclick = function() {
console.log(1)
}
$(this).addClass('uncheck-to-remove').attr('title',Drupal.t('Uncheck to remove this item')).click(function() {
$(this).closest('tr').hide(500);
});
});
}
// }
};
// Create a new ajax command, ervw_draggable that is called to make the rows
// of the widget draggable.
Drupal.ajax.prototype.commands.ervw_draggable = function(ajax, response, status) {
$('#' + response.selector + ' tr').each(function(){
var el = $(this);
Drupal.tableDrag[response.selector].makeDraggable(el.get(0));
el.find('td:last').addClass('tabledrag-hide');
if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
el.find('.tabledrag-handle').hide();
}
else {
el.find('td:last').hide();
}
});
};
})(jQuery);
你不需要为此编写任何代码(隐藏部分必须用 js 代码 atm 编写),这只是配置。
要不显示在您创建的视图中填充的模态中已经选择的项目,您必须在节点的 nid 上有一个上下文过滤器。编辑此上下文过滤器并选中 "More" 菜单下的 "Exclude"(在添加多个值旁边)。
查看此视频:http://codekarate.com/daily-dose-of-drupal/entity-reference-view-widget 在 8:00 标记处。该视频几乎解释了此小部件的所有基本配置。