backbone-forms with conditional fields

前端 未结 2 781
挽巷
挽巷 2021-01-05 16:27

First of all thanks to the guys of backbone-forms who made a tool which perfectly integrates in the backbone.js framework.

I\'m using backbone.js with the backbone-f

2条回答
  •  清歌不尽
    2021-01-05 17:18

    You can bind events to the select element and have them toggle the visibility of other form elements.

    Try this:

    $(function() {
    
        //The form
        var form = new Backbone.Form({
            schema: {
                inputType: { type: 'Select', options: ['line', 'area'] },
                line: 'Text',
                area: 'TextArea'
            }
        }).render();
    
        form.fields['area'].$el.hide();
    
        form.on('inputType:change', function(form, editor) {         
            form.fields['line'].$el.toggle();
            form.fields['area'].$el.toggle();
        });
    
        //Add it to the page
        $('body').append(form.el);
    });
    

    Here's some live code: http://jsfiddle.net/shioyama/grn6y/

    Derived from this: https://groups.google.com/d/topic/backbone-forms/X5eVdTZWluQ/discussion

提交回复
热议问题