Python 带deform的动态表单

Python 带deform的动态表单,python,pylons,colander,deform,Python,Pylons,Colander,Deform,使用deform制作表单,whould希望根据用户的选择更改pageShema类。 例如,如果他从selectwidget中选择选项1,则向他显示一组字段,如果是其他选择,则显示另一组字段。 如何做到这一点 您可以使用jquery并使用“name”属性进行选择。 此外,您还可以使用jquery“parent()”函数获取您感兴趣的显示/隐藏输入的容器 例如,在模式中执行以下操作: # This is the "<select>" choices = (('yes','Yes'),

使用deform制作表单,whould希望根据用户的选择更改pageShema类。 例如,如果他从selectwidget中选择选项1,则向他显示一组字段,如果是其他选择,则显示另一组字段。
如何做到这一点

您可以使用jquery并使用“name”属性进行选择。 此外,您还可以使用jquery“parent()”函数获取您感兴趣的显示/隐藏输入的容器

例如,在模式中执行以下操作:

# This is the "<select>"
choices = (('yes','Yes'),
           ('no', 'No'))
bar = colander.SchemaNode(colander.String(),
                          widget=deform.widget.SelectWidget(values=choices))

# This is the input that should appear only when the "yes" value is selected
foo = colander.SchemaNode(colander.String())
#这是
选项=(‘是’、‘是’),
(‘否’、‘否’)
bar=colander.schemaAnode(colander.String(),
widget=deform.widget.SelectWidget(值=选项))
#这是仅当选择“是”值时才应显示的输入
foo=colander.schemaNo(colander.String())
然后,在模板中添加以下内容:

<script>
$( document ).ready(function() {

// ensure that the "foo" input starts hidden
var target = $("input[name=foo]").parent().parent();
target.hide();

$("select[name=bar]").on('change', function(){
    var valueSelected = this.value;
    if (valueSelected == "yes") {
      target.show();
    } else {
      target.hide();
    }
});



});
</script>

$(文档).ready(函数(){
//确保“foo”输入开始隐藏
var target=$(“输入[name=foo]”).parent().parent();
target.hide();
$(“选择[name=bar]”)。在('change',function()上{
var valueSelected=此值;
如果(valueSelected==“是”){
target.show();
}否则{
target.hide();
}
});
});

您可以使用jquery并使用“name”属性进行选择。 此外,您还可以使用jquery“parent()”函数获取您感兴趣的显示/隐藏输入的容器

例如,在模式中执行以下操作:

# This is the "<select>"
choices = (('yes','Yes'),
           ('no', 'No'))
bar = colander.SchemaNode(colander.String(),
                          widget=deform.widget.SelectWidget(values=choices))

# This is the input that should appear only when the "yes" value is selected
foo = colander.SchemaNode(colander.String())
#这是
选项=(‘是’、‘是’),
(‘否’、‘否’)
bar=colander.schemaAnode(colander.String(),
widget=deform.widget.SelectWidget(值=选项))
#这是仅当选择“是”值时才应显示的输入
foo=colander.schemaNo(colander.String())
然后,在模板中添加以下内容:

<script>
$( document ).ready(function() {

// ensure that the "foo" input starts hidden
var target = $("input[name=foo]").parent().parent();
target.hide();

$("select[name=bar]").on('change', function(){
    var valueSelected = this.value;
    if (valueSelected == "yes") {
      target.show();
    } else {
      target.hide();
    }
});



});
</script>

$(文档).ready(函数(){
//确保“foo”输入开始隐藏
var target=$(“输入[name=foo]”).parent().parent();
target.hide();
$(“选择[name=bar]”)。在('change',function()上{
var valueSelected=此值;
如果(valueSelected==“是”){
target.show();
}否则{
target.hide();
}
});
});

请在问题中添加一些代码显示我们遇到了什么问题请在问题中添加一些代码显示我们遇到了什么问题非常好的解决方案。简单和聪明。对于更全面的解决方案,您可以使用类似于非常好的解决方案。简单和智能。对于更全面的解决方案,您可以使用