Snippi
A super awesome snippet tool.
- 1.
<script>
- 2.
jQuery(document).ready(function( $ ) {
- 3.
// Prepends a checkbox to the field and hides the quantity box for fields with custom class .checkbox_qty
- 4.
// Add this code to an HTML Content form field in Gravity Forms
- 5.
- 6.
$('.checkbox_qty').each(function() {
- 7.
var ck_name = 'ck_'+$(this).attr("id");
- 8.
var checkbox = '<input type="checkbox" value="Yes" class="add_option" id="'+ck_name+'" />';
- 9.
$(this).prepend(checkbox);
- 10.
$(this).find('.gfield_label').attr("for", ck_name);
- 11.
$(this).find('.ginput_quantity_label').css("display","none");
- 12.
$(this).find('.ginput_quantity').css("visibility","hidden");
- 13.
});
- 14.
- 15.
$('.add_option').change(function(){
- 16.
var qty = this.checked ? '1' : '0';
- 17.
var field = $(this).parent().find('.ginput_quantity');
- 18.
field.val(qty);
- 19.
});
- 20.
- 21.
});
- 22.
</script>