Hi,
I have this script running on my site in my functions.php
// For each GF list item, make the first column read-only and increment with +1
function gf_readonly() {
if (is_product()) {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$(".gform_wrapper .gf-readonly .gfield_list_cell:first input").attr("readonly", "");
$(".gform_wrapper .gf-readonly .gfield_list_cell:first input").val( function(i, oldval) {return ++oldval;});
});
</script>
<?php
}
}
add_action('wp_footer', 'gf_readonly');
Specifically, I need help with this part
$(".gform_wrapper .gf-readonly .gfield_list_cell:first input").val( function(i, oldval) {return ++oldval;});
I am using this snippet [[LINK href="http://gravitywiz.com/set-number-of-list-field-rows-by-field-value/"]]Set Number of List Field Rows by Field Value | Gravity Wiz[[/LINK]] to automatically spawn a number of Field List rows depending on the value of another field in my form.
All works fine, expect that when I input, for example, "3" in my input field, the additionally added Field List items are not incremented with numbers.
Most likely because my jQuery script needs to be fired again somehow, I just don't know how.
See a video demo here, then it all makes more sense: [[LINK href="https://www.dropbox.com/s/x3a5x7m52o20adx/Google%20Chrome%20-%20Asbest%20-%20Gel%20tape.mov?dl=0"]]Demo Video[[/LINK]]
Basically the newly added rows need to have "2" and "3", "4", "5", etc. inserted automatically when a number is specifed in the input field above the list field.
Jayaram Y answers:
Hi Cruiseback,
I have done this in my test environment. Please check here: http://dev.igenero.in/tuscan/?page_id=5
Attached screenshot as well
cruiseback comments:
Hi Jayram,
Great, I copied your script from your source and it seems to work perfectly, money goes to you.
Thanks.
Reigel Gallarde answers:
I need to see the page... but here's a guess... add this..
jQuery(document).on('click','.add_list_item',function(){
var tr = jQuery(this).closest('tr');
tr.find('[type=text]').first().val(tr.index()+1);
});
cruiseback comments:
Hi Reigel,
The site is on my localhost right now, I can probably put it live somewhere later today.