Home › Forums › Add-ons › Options Page › DatePicker – Disable Dates insert into Js › Reply To: DatePicker – Disable Dates insert into Js
// PHP
// register a script
// see https://developer.wordpress.org/reference/functions/wp_register_script/
wp_register_script($handle, $src, $deps, $ver, $in_footer);
// build JS object
// here I am assuming I have a repeater with 2 sub fields
// Let's assume they are two date fields
// initialize my object as an array
// it will hold the rows of the repeager
$object = array();
if (have_rows('repeater')) {
while (have_rows('repeater')) {
the_row();
// add row to array
$object[] = array(
'start_date' => get_sub_field('start_date'),
'end_date' => get_sub_field('end_date')
);
}
}
// localize script
$object_name = 'my_js_object';
wp_localize_script($handle, $object_name, $object);
// enqueue the script
wp_enqueue_script($handle);
// JS File
if (my_js_object.length > 0) {
for (i=0; $i<my_js_object.length; i++) {
var row = my_js_object[i];
// do something with the row
console.log(row['start_date'];
console.log(row['end_date'];
// the above lines could also use this syntax
console.log(row.start_date);
console.log(row.end_date);
}
}
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.