Paulo Freitas
Paulo Freitas

Reputation: 13649

Creating dynamic form elements with jQuery Mobile

Ok, perhaps that was answered before, but I wasn't able to found anything through search...

I'm new to jQuery Mobile and I'm trying to dynamically add radioboxes to one <fieldset> container through a page, as you can see in this fiddle: http://jsfiddle.net/4V3Tm/4/

It's working. But for some reason I don't know, dynamically added choices didn't get styled as normal radioboxes. Am I missing something? BTW, shouldn't them all expand to the page width? (well, I'm totally noob yet...)

Thank you in advance.

Upvotes: 3

Views: 4322

Answers (1)

rkmax
rkmax

Reputation: 18135

check this fiddle http://jsfiddle.net/YUvG9/ or check an update of yours http://jsfiddle.net/4V3Tm/4/ maybe the problem is you call .trigger('create') many times

$(document).on('pageinit', '#home', function () {
    var current = 3;

    $('#home input[type=button]').click(function () {
        current++;        
        $('#choices .ui-controlgroup-controls')
            .append(
                $('<input/>', {
                        'type': 'radio',
                        'name': 'choice',
                        'id': 'choice' + current,
                        'value': current,
                        'data-theme': 'd'
                    })
                    .append(
                        $('<label/>', {
                            'for': 'choice' + current
                        })
                        .text('Choice ' + current)
                )
            );

        $("#home").trigger('create')
    });
});

Upvotes: 7

Related Questions