asked on June 16, 2021 Show version history

This may a bit odd but is there a way to figure out what collections 'add' button was clicked without needing the class name of the collection or the 'q#'. 

I'm trying to write code that is flexible so we can reuse it.  The collections would have address fields in them that we want to default the state value of the last row added without touching changing other state values. I was thinking of using $(this).parents('???'), but could not get that working because I could not figure out what I should put in the '????' spot.

 

$('.cf-collection-append').click(function () { 
   // here I want to to be able to access the fields and their values 
  });

 

EDIT I figured it out. This works with the assumption there is only one address per collection so it would need modified if each collection had more than one address.

  $('.cf-collection-append').click(function () { 
    var refID = $(this)[0].getAttribute('ref-id');

     /* defaultState is a global variable */
    $('#' + refID + ' .State:last').val(defaultState);

  });   

 

EDIT 2: even better replace line 5 above with the following and it will update all State values of the last row in the collection

$('#' + refID + ' ul.rpx:last .State').val(defaultState);

 

1 0