Home › Forums › General Issues › JS event listener for sub fields › Reply To: JS event listener for sub fields
Hi @hube2,
That is very close to what I ended up using. The main difference is I didn’t have to target the row as it’s a group not a repeater. I also didn’t use the trigger for field that was changed, but I will add that.
This is what I used:
$(document).on('change', '[data-key="field_64d372692bcc4"] .acf-input select', function() {
var field = acf.getField('field_64d372692bcc4');
var racedayId = field.val();
var data = {
action: 'newbury_admin_get_raceday_details',
racedayId: racedayId,
}
$.ajax({
url: acf.get('ajaxurl'),
data: acf.prepareForAjax(data),
type: 'post',
dataType: 'json',
success: function( json ){
var result = json;
if(result[0].date) {
var date = result[0].date, dateSplit = date.split('-');
$('[data-key="field_64d224149988e"] .acf-input input[type=hidden]').val(dateSplit[2]+dateSplit[1]+dateSplit[0]);
$('[data-key="field_64d224149988e"] .acf-input input[type=text]').val(dateSplit[0]+'/'+dateSplit[1]+'/'+dateSplit[2]);
$('[data-key="field_64d2245f9988f"] .acf-input input[type=text]').val(result[0].Racetype);
$('[data-key="field_64d2249899890"] .acf-input input[type=url]').val(result[0].url);
$('[data-key="field_64d224b499891"] .acf-input input[type=text]').val(result[0].name);
}
}
});
});
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.