如何在 Drupal 7 中从自定义搜索表单中删除属性值



我已经为搜索块安装了自定义搜索模块。 在搜索表单中,有一个文本字段具有具有空的值属性。 它显示了可访问性问题,这就是我想删除它的原因。 我应该为此做什么。 请帮忙。

任何人都可以解决此类问题。

请参阅源代码快照。

源代码快照

对于文本字段,value 属性是强行添加到theme_textfield()中,因此唯一的方法是在您的主题中覆盖该函数并删除那段代码:

function YOURTHEME_textfield($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'text';
// remove value form array
element_set_attributes($element, array('id', 'name', 'size', 'maxlength'));
_form_set_class($element, array('form-text'));
$extra = '';
if ($element['#autocomplete_path'] && !empty($element['#autocomplete_input'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#autocomplete_input']['#id'];
$attributes['value'] = $element['#autocomplete_input']['#url_value'];
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = '<input' . drupal_attributes($element['#attributes']) . ' />';
return $output . $extra;
}

希望这对您有所帮助...

您可以使用 jquery 将其删除。使用以下代码。

$('.custom-search-box').removeAttr('value');

我想这对你有帮助。

最新更新