我使用的是Zend Frameworks ViewHelpers。我正在尝试传递一些东西,以便在SELECT中设置禁用属性。例如,如果
$countries = array(1=>'Select Option', 2=>'us', 3=>'uk')和formSelect('country','us',null,$this->countries)
我需要启用第一个选项,即‘选择选项’
你有什么想法吗?
感谢你的帮助
发布于 2010-08-31 21:24:04
我不认为你可以禁用一个元素?如果你禁用了它,那为什么还要拥有它呢?
您只能禁用整个<select>输入。
建议您编写验证以不接受第一个元素。
在OP关于能够做到这一点的评论之后编辑
这是另一个答案
// Get the countries element (do this after adding your options), then set the
// attribute disable for option '1'
$form->getElement("countries")->setAttrib("disable", array(1));这是建议的here
发布于 2013-01-02 23:26:53
有一种方法可以通过Zend_Form做到这一点(至少在我当前的版本1.11上是这样):
$this->addElement
(
"select","selectName",
array("multiOptions"=>array("one","two","three"), "disable"=>array(0,1))
);该选项将禁用前两个选项。
发布于 2010-09-01 15:25:20
功劳归功于jakenoble。
只是重新格式化了代码,使用formSelect-viewhelper而不是form-element。
<?php
$countries = array(1 => 'Select Option', 2 => 'us', 3 =>'uk');
echo $this->formSelect('country', 2, array('disable' => array(1)), $countries)这将导致:
<select name="country" id="country">
<option value="1" label="Select Option" disabled="disabled">Select Option</option>
<option value="2" label="us" selected="selected">us</option>
<option value="3" label="uk">uk</option>
</select>https://stackoverflow.com/questions/3609355
复制相似问题