Support

Account

Home Forums Backend Issues (wp-admin) How get value by field name in JavaScript API?

Solved

How get value by field name in JavaScript API?

  • Tried in browser console:

    acf.getField('my_field_name').val() - undefined
    acf.getField({name:'my_field_name'}).val() - undefined
    acf.getFields({name:'my_field_name'})[0].val() - actual value

    What would be the correct and simple way to get a value by field name (not field key)?

    ACF Pro 5.8.4

  • You can’t use the field name, you need to use the field key. Fields are not identified in the DOM by name. Names can be duplicated, field keys are unique.

  • Ok, thanks for explaination.

    Using this workaround (edited) for now:

    
    var val = (val = acf.getFields({name:'my_field_name'}).shift()) ? val.val() : '';
    
  • Thank you! It worked for me.

    For repeater fields, do you know I can get value from each field and form an array?

    Many thanks!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘How get value by field name in JavaScript API?’ is closed to new replies.