不在同一行的单选按钮值

发布于 2024-12-04 10:33:10 字数 268 浏览 0 评论 0原文

我正在构建一个“自助餐菜单列表”表单,其中有很多“菜单”单选按钮选项。 但是我注意到所有这些值都是“内联”的,就像本例中一样: http:// demo.atk4.com/demo.html?t=14

我想知道,首先如何在每个值上添加换行符,然后,如何通过添加某种类型来模拟组< p> < /p>特定选项值之间(逻辑分组)。

提前致谢!

I'm building a "buffet menu list" form which has a lot of options for the "menu" radiobutton.
However I noted that all those values are "inline" just like in this example: http://demo.atk4.com/demo.html?t=14

I'd like to know in first instance how could I add a line break on every value, and then, how could I simulate groups by adding some sort of < p> < /p> between specific option values (logical grouping).

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2024-12-11 10:33:10

我能想到的解决方案有两种。

查看此处的示例以获得一些灵感:

http://agiletoolkit.org/doc/grid/columns

1. 将自定义字段添加到网格中

首先,创建一个没有标记的表单:

$form = $this->add('Form',null,null,array('form_empty'));

接下来,将网格添加到如下所示的表单中:

$grid = $form->add('Grid'); // or MVCGrid if you are using models

添加用于选择的列:

$grid->addColumn('template','selection')
     ->setTemplate('<input type=radio name=selection value="<?$id?>"/>');

最后 - 确保列“选择”是第一个(或最后一个)

$grid->addOrder()->move('selection','first')->now();

最后需要手动查看POST 数据,因为它不是真正的表单列。

if($form->isSubmitted()){
    $this->js()->univ()->successMessage('Selection is '+((int)$_POST['selection']))
          ->execute();
}

您必须记住,直接访问 POST 会使您面临注入攻击,并且您必须正确验证它。网格也必须位于表单内,但是您可以将提交按钮放置在页面上的任何其他位置。您还可以使用“Form_Plain”,请参阅“http://agiletoolkit.org/whatsnew”的示例。

2. 使用 JavaScript 和隐藏字段

在此示例中,您可以添加一堆单选按钮元素并将它们绑定到表单。我还在这里使用“Lister”而不是“Grid”,当然您可以混合搭配这些方法。

$form = $this->add('Form');
$selection = $form->addField('line','selection');
// can be placed anywhere.

$menu = $this->add('MVCLister',null,null,array('view/menu'));
$menu->setModel('MenuItems'); 

$menu->js(true)->find('input[type=radio]')->click(
    $selection->js()->_enclose()->val(
        $this->js()->_selectorThis()->val()
    );
);
// produces $('#menu_id').find('input[type=radio]').click(function(){
//    $('#selection_id').val( $(this).val() );
// }

您的 view/menu.html 模板文件可能如下所示:

<div class="menu-container">
<?rows?><?row?>
    <div><input type="radio" name="anything" value="<?$id?>"> <?$name?> </div>
<?/row?><?/rows?>
</div>

编辑:适用于 Fernando 的代码

$grid->addColumn('template','Menu')
    ->setTemplate('<input type=\'radio\' name=\'selection\' value="<?$value?>"/> <?$value?>');
if($form->isSubmitted()){
    $this->js()->univ()
         ->successMessage('Hoy: <b>'.$_POST['selection'].'</b>')->execute();
}

There are two solutions I can think of.

Look at the examples here for some inspiration:

http://agiletoolkit.org/doc/grid/columns

1. Adding custom field to grid

First, create a form with no mark-up:

$form = $this->add('Form',null,null,array('form_empty'));

Next, add Grid into a form like this:

$grid = $form->add('Grid'); // or MVCGrid if you are using models

Add a column for selection:

$grid->addColumn('template','selection')
     ->setTemplate('<input type=radio name=selection value="<?$id?>"/>');

Finally - make sure the column 'selection' is first (or last)

$grid->addOrder()->move('selection','first')->now();

Finally you need to manually look into the POST data, because it's not a real form column.

if($form->isSubmitted()){
    $this->js()->univ()->successMessage('Selection is '+((int)$_POST['selection']))
          ->execute();
}

You must remember that accessing POST directly exposes you to injection attack and you must validate it properly. Grid also MUST be inside the form, however you can place submit button anywhere else on your page. You can also use "Form_Plain", see "http://agiletoolkit.org/whatsnew" for an example.

2. Using JavaScript and hidden field

In this example you can add a bunch of Radio button elements and tie them to a form. I've also using "Lister" here instead of "Grid", of course you can mix-and-match those approaches.

$form = $this->add('Form');
$selection = $form->addField('line','selection');
// can be placed anywhere.

$menu = $this->add('MVCLister',null,null,array('view/menu'));
$menu->setModel('MenuItems'); 

$menu->js(true)->find('input[type=radio]')->click(
    $selection->js()->_enclose()->val(
        $this->js()->_selectorThis()->val()
    );
);
// produces $('#menu_id').find('input[type=radio]').click(function(){
//    $('#selection_id').val( $(this).val() );
// }

Your view/menu.html template file could look like this:

<div class="menu-container">
<?rows?><?row?>
    <div><input type="radio" name="anything" value="<?$id?>"> <?$name?> </div>
<?/row?><?/rows?>
</div>

EDIT: code which worked for Fernando

$grid->addColumn('template','Menu')
    ->setTemplate('<input type=\'radio\' name=\'selection\' value="<?$value?>"/> <?$value?>');
if($form->isSubmitted()){
    $this->js()->univ()
         ->successMessage('Hoy: <b>'.$_POST['selection'].'</b>')->execute();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文