我在这里使用HTML :: FormHanlder。 我试图用渲染单选按钮获得不同的输出(using this method)。字段声明是这样的:渲染RadioGroup元素
has_field 'xxx' => (type => 'Select', widget => 'RadioGroup', build_label_method => \&build_label);
sub build_label {
my $self = shift;
return $self->name;
}
的问题是,唯一的<label>
在分组报头元素:
<label for="xxx">Lorem ipsum</label>
,
所以它改变了。
单选按钮保持不变像<input type="radio" name="xxx" id="xxx" value="2"/> I'm not changed
所以很自然我想知道如何更改自动渲染“我没有改变”(在这种情况下),其走后<input/>
下面是一个例子,以文本使其更清楚:
<label for="0.xxx">This is the only part that gets changed with sub build_label</label>
<label class="radio" for="0.xxx.0">
<input type="radio" name="0.xxx" id="0.xxx.0" value="2"/>
How to change rendering method of this part?
</label>
<label class="radio" for="0.xxx.1">
<input type="radio" name="0.xxx" id="0.xxx.1" value="1"/>
And this one?
</label>
感谢您花时间注册并回答问题,您让我走上正轨。不知何故'options_method'没有像预期的那样工作(我无法获得'$ self-> schema'等),但是'sub options_'完成了这项工作。 P.S.我真的去寻找源代码,试图创建一个新的Moose :: Role,它具有'HTML :: FormHandler :: Widget :: Field :: RadioGroup'',所以我可以修改'wrap_radio'方法,但是我想我不能在那里使用DBIx :: Class,所以我不得不尝试其他的:) –
'options_method'提供了一个字段方法,所以这个模式在$ self-> form-> schema中。 'options_'方法是一种表单方法,因此该模式位于$ self> schema中。可以在RadioGroup和CheckboxGroup小部件中使用'label_method'回调,但由于可以使用正确的标签创建选项,因此我不清楚是否需要这种回调。 –
gshank