【发布时间】:2012-01-19 11:44:24
【问题描述】:
我如何在 symfony 中做到这一点?
http://dorward.me.uk/tmp/label-work/example.html
当我点击输入字段用户名时。文字消失。如果我不输入任何内容并单击其他地方,文本将再次出现。我如何在 lib/forms/ 中的 symofny 中做到这一点。
感谢您的建议!
寻宝者
【问题讨论】:
标签: forms symfony1 symfony-1.4
我如何在 symfony 中做到这一点?
http://dorward.me.uk/tmp/label-work/example.html
当我点击输入字段用户名时。文字消失。如果我不输入任何内容并单击其他地方,文本将再次出现。我如何在 lib/forms/ 中的 symofny 中做到这一点。
感谢您的建议!
寻宝者
【问题讨论】:
标签: forms symfony1 symfony-1.4
这不是 symfony - 它的 javascript ... 看看源代码(使用 jQuery)
HTML:
<div class="slim-control">
<label for="username"> Username </label>
<input name="username" id="username">
</div>
<div class="slim-control">
<label for="password"> Password </label>
<input name="password" id="password" type="password">
</div>
JavaScript:
(function () {
var nonEmpty = "non-empty";
var inputs = jQuery('.slim-control input');
var setLabelStyle = function setLabelStyle () {
var label = jQuery(this);
if (label.val().length) {
label.addClass(nonEmpty);
} else {
label.removeClass(nonEmpty);
}
};
inputs.focus(function () {
jQuery(this).addClass(nonEmpty);
});
inputs.blur(setLabelStyle);
inputs.each(setLabelStyle);
}());
因此,如果您想这样做 - 例如,您需要将 javascript 添加到模板 (indexSuccess.php) - 您可能需要修改 ids / classes 以满足您的本地需求
您可以创建以下表单 - 这将与上述表单匹配(未经测试):
$this->form = new sfForm();
$this->form->setWidgets(array(
'username' => new sfWidgetFormInputText(),
'password' => new sfWidgetFormInputPassword()
));
创建表单(实际上是所有 Symfony)在这里都有很好的记录 -> http://www.symfony-project.org/gentle-introduction/1_4/en/10-Forms
【讨论】:
'input' => new sfWidgetFormInputText(array(), array('size' => '100', 'maxlength' => '255', 'value' => 'Some text', 'onblur' =>"if(this.value == '') { this.value='Some text'}", 'onfocus' =>"if (this.value == 'Some text') {this.value=''}")),
这要短得多!注意“某些文本”是相同的!
如果您需要传递更多信息,请查看 Symfony 形式的 SetWidgetsHtml:(向下滑动) http://www.symfony-project.org/forms/1_4/en/01-Form-Creation
【讨论】: