小编Aus*_*ams的帖子

twig form widget动态选择表单字段

我有一个表单,可以根据我的数据库中的实体动态生成字段(我的实体是课程).对于每个新课程,它会添加一个表单字段来修改它的排序顺序.我的问题是,如何在我的课程表中动态显示这些单独的表单字段?

我的形式逻辑:

foreach ($entities as $id => $course) { //$id key included to show you courses key value

  $formBuilder->add($course->getId(), 'text', array(
      'data' => $course->getsortOrder(),
      'label' => false,
      'attr' => array('class' => 'sort' /*, 'style' => 'visibility:hidden;'*/ )
  ));
}
Run Code Online (Sandbox Code Playgroud)

我的jQuery修改了表单字段:

$(document).ready(function () {
  $(".records_list tbody").sortable({items: "tr"},
  {stop: function(event, ui) {
      $(".sort").each(function(index) {
        $(this).val(index);
      });
    }
  });
});

 /* I tested the proper functionality of this jQuery by putting 
  <input type="text" class="sort" value="{{ entity.sortOrder }}">
  into the <td> that sort order …
Run Code Online (Sandbox Code Playgroud)

forms symfony twig

2
推荐指数
1
解决办法
2833
查看次数

标签 统计

forms ×1

symfony ×1

twig ×1