欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal form cck api date size form alter 更改日期输入字段的大小?

更改日期输入字段的大小?

有什么办法重写“文本”日期输入字段的大小吗?

我试过以下:

/**
* Adjust text fields so they fit in the "Find a Show" block
*/
function tw_form_views_exposed_form_alter(&$form, $form_state) {
  if ($form['#id'] == 'views-exposed-form-find-a-show-list-page-1') {
  	//dpm($form); //does not work
  	$form['submit']['#value'] = 'Find Shows'; //this works!
	$form['field_opening_dt_value']['value']['#size'] = '11'; //doesn't work (works for popup)
  	$form['field_closing_dt_value']['value']['#size'] = '11'; //doesn't work (works for popup)
  	//print '<pre>'; print_r($form); print '</pre>'; //this works
  	
  } //I'm fed up with this!
}

注释

artofeclipse的头像

如果这是工作在print_r()和dosen't工作在html输出这可能是由另一个模块“日期”模块可能尝试添加.install或实现hook_enable()和内部添加

<?php
db_query("UPDATE {system} SET weight = [yournumber] WHERE name = 'yourmodulename'");
?>

其中[yournumber]是一个整数值,使您的模块是最后一个模块在表单输出上做修改。

我希望这帮助你。

donpwinston的图片

谢谢,但它仍然没有工作。我认为也许cck和/或日期模块只是忽略#size属性。

我诉诸使用CSS属性“width”来覆盖输入标签的“length”属性。

更简单总是更好。

donpwinston的图片

我放弃了这一点,并使用CSS来设置我的日期输入控件的<input>标签的宽度。

在表单控件上使用CSS是错误的。显示应该留给浏览器和客户端的操作系统。

但是你得做你要做的事。

更简单总是更好。

来自 https://www.drupal.org/node/1258952


 

Alter size of date input fields?

 

Is there any way to override the size of a "text" date input field?

I've tried the following:

/**
* Adjust text fields so they fit in the "Find a Show" block
*/
function tw_form_views_exposed_form_alter(&$form, $form_state) {
  if ($form['#id'] == 'views-exposed-form-find-a-show-list-page-1') {
  	//dpm($form); //does not work
  	$form['submit']['#value'] = 'Find Shows'; //this works!
	$form['field_opening_dt_value']['value']['#size'] = '11'; //doesn't work (works for popup)
  	$form['field_closing_dt_value']['value']['#size'] = '11'; //doesn't work (works for popup)
  	//print '<pre>'; print_r($form); print '</pre>'; //this works
  	
  } //I'm fed up with this!
}

Comments

artofeclipse的头像

If this is working in print_r() and dosen't work out in the html output this might be caused by another module "date" module maybe try to add .install or implement hook_enable() and inside it add

<?php
db_query("UPDATE {system} SET weight = [yournumber] WHERE name = 'yourmodulename'");
?>

where [yournumber] is an integer value that make your module to be the last module to do modification on the form output.

I hope this help you.

donpwinston的图片

Thanks, but it still did not work. I think maybe the cck and/or date module simply ignore the #size property.

I resorted to using the CSS property "width" to override the "length" attribute of the the input tag.

Simpler is always better.

donpwinston的图片

I've given up on this and used CSS to set the width of the <input> tags for my date input controls.

It's wrong to use CSS on form controls. The display should be left to the browser and the client's OS.

But you got to do what you got to do.

Simpler is always better.

来自  https://www.drupal.org/node/1258952


普通分类: