I need to fill form fields with post_meta from an ajax response.
Everything works properly.
I could hard-code the swapping of each piece of data.meta into its form field. But that approach is not reusable.
Is there a way to loop through the data.meta instead?
In some cases, there may not be meta for all the form fields. And in some cases, there may be meta that is not applicable to the form.
This is for a form in a bootstrap modal window.
$.ajax({
...
success: function (data) {
if (data.status === 'success') {
$('#title').val(data.title);
$.each(data.meta, function(key,value) {
alert(key + '---' + value[0]);
// if key is a form element, add the value to that element
// if key is a form element that is a select dropdown,
// then mark that option as selected
});
}
}
});