Aligning checkboxes

64 views
Skip to first unread message

Sangharsh Boudhh

unread,
Dec 16, 2014, 6:13:52 AM12/16/14
to jquery...@googlegroups.com
Hi,

Using "checkboxes" types with jQuery.dForm renders "<input>" and "<label>" tag one after the other and display on different line.


I would like to have <input> tag wrapped inside <label> tag and displayed on the same line.
E.g. <label><input type="checkbox" name="checkbox" value="value">Text</label>

Please guide on how to re-structure the JSON OR modify CSS in order to achieve this.


Thanks,
Sangharsh

Sangharsh Boudhh

unread,
Dec 16, 2014, 6:32:49 AM12/16/14
to jquery...@googlegroups.com
If adding a type or subscriber can achieve desired result, that is also welcome.

David Luecke

unread,
Dec 16, 2014, 6:39:31 AM12/16/14
to jquery...@googlegroups.com
That can just be done with simply adding another `options` subscriber:

$.dform.subscribe("options", function(options, type) {
    $(this).find('label').each(function() {
        var el = $(this);
        el.prepend(el.prev())
    });
    
    return $(this);
});


--
You received this message because you are subscribed to the Google Groups "jQuery dForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jquery-dform...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sangharsh Boudhh

unread,
Dec 16, 2014, 7:55:31 AM12/16/14
to jquery...@googlegroups.com
Hi Daff,

This is working fine for wrapping <input> inside <label>.

However, "name" attribute is now missing from <input> tag, which is breaking form encoding on POST.
Can you please suggest, how to have "name" attribute back?

Earlier:
<input type="checkbox" class="ui-dform-checkbox" value="js" name="why">

Now:
<input type="checkbox" class="ui-dform-checkbox" value="js">

David Luecke

unread,
Dec 16, 2014, 9:15:05 AM12/16/14
to jquery...@googlegroups.com
Hm, this is probably because the [post] subscriber adds the name only to direct children (see https://github.com/daffl/jquery.dform/blob/master/src/dform.core.js#L207). You can add another one that fixes this :

$.dform.subscribe('[post]', function(options, type) {
    if (type === "checkboxes" || type === "radiobuttons") {
        this.find('input').attr('name', options.name);
    }
});

Sangharsh Boudhh

unread,
Dec 16, 2014, 9:20:17 AM12/16/14
to jquery...@googlegroups.com
Yes. This solves it.

Thanks a lot.
Reply all
Reply to author
Forward
0 new messages