diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php
index 9a73776..5920b2d 100644
--- a/plugins/cipf_plugin/cipf_plugin.php
+++ b/plugins/cipf_plugin/cipf_plugin.php
@@ -4,7 +4,7 @@ Plugin Name: hggg_cipf
Plugin URI:
Description:
Author: hugogogo
-Version: 0.5.11.2
+Version: 0.5.11.3
Author URI:
*/
diff --git a/plugins/fbpatch/js/dates.js b/plugins/fbpatch/js/dates.js
index 3d4a958..19d50e7 100644
--- a/plugins/fbpatch/js/dates.js
+++ b/plugins/fbpatch/js/dates.js
@@ -1,8 +1,10 @@
/*
* overriding the datepicker function to intercept the arguments
* -> https://stackoverflow.com/questions/26667720/how-to-get-the-selected-date-from-jquery-datepicker
-* then create an hidden input with the date in acf format 'yymmdd'
-*
+* then create an false input that will mask the real one
+* and put the original date format on the false element,
+* while transforming the real one with the acf format 'Ymd'
+*
* another solution would be to find the elements with the datepicker, and add the onSelect here
*
*/
@@ -11,14 +13,11 @@ const original_datepicker = jQuery.fn.datepicker;
// override the datepicker function
jQuery.fn.datepicker = function(options) {
/*
- * first get the target element and create the hidden input
+ * first creates the fake input
*
*/
- const hidden_id = 'acf_date_hidden_' + this.attr('id');
- const hidden_name = 'acf_date_hidden_for_' + this.attr('name');
- if (jQuery('#' + hidden_id).length === 0) {
- jQuery(``).insertAfter(this);
- }
+ create_fake_date_input(options, this);
+
/*
* then override the options to add action on select date :
@@ -28,13 +27,60 @@ jQuery.fn.datepicker = function(options) {
options.onSelect = function(date_text, inst) {
const acf_date_format = "yymmdd";
const selected_date = jQuery(this).datepicker('getDate');
- console.log("-- selected_date:", selected_date);
const formated_date = jQuery.datepicker.formatDate(acf_date_format, selected_date);
- const hidden_id = 'acf_date_hidden_' + inst.id;
- jQuery('#' + hidden_id).val(formated_date);
+ const fake_id = 'acf_date_fake_' + inst.id;
+ jQuery('#' + fake_id).val(date_text);
+ jQuery(this).val(formated_date);
}
// call the original datepicker function with the updated option
return original_datepicker.call(this, options);
};
+
+
+/*
+* creates the false element
+* place it above the real one to hide it
+*
+*/
+function create_fake_date_input(options, element) {
+ const fake_id = 'acf_date_fake_' + element.attr('id');
+ // false element already exists
+ if (jQuery('#' + fake_id).length !== 0) {
+ return;
+ }
+
+ const fake_name = 'acf_date_fake_for_' + element.attr('name');
+ const original_date_string = element.val();
+ const fake_value = original_date_string;
+
+ /*
+ * we position the hidden element right in top of the real datepicker one
+ * it might nor work in some situation, but so far it's good
+ * then we remove pointer events, so that clicking on it actually clicks on the real input
+ *
+ */
+ let fake_style = `
+ border: 1px solid blue;
+ position: absolute;
+ top: 0px;
+ left: 100px;
+ pointer-events: none;
+ `;
+ const font_weight = element.css('font-weight');
+ if (font_weight) {
+ fake_style += `font-weight: ${font_weight};`;
+ }
+
+ /*
+ * gives the parent element a defined position if needed
+ * then create the false input above the real one
+ *
+ */
+ if (element.parent().css('position') === 'static') {
+ element.parent().css('position', 'relative');
+ }
+ jQuery(``).insertAfter(element);
+}
+
diff --git a/plugins/fbpatch/php/patches/dates.php b/plugins/fbpatch/php/patches/dates.php
index 54ede73..ae2f663 100644
--- a/plugins/fbpatch/php/patches/dates.php
+++ b/plugins/fbpatch/php/patches/dates.php
@@ -54,24 +54,24 @@ if (!defined('ABSPATH')) {
* and if returned it will let the function go on to try to retrieve the value
*
*/
-function try_get_acf_date($value, $post_id, $field) {
- $acf_date_class = Fbpatch::ACF_DATE_CLASS;
- if ($field['type'] !== 'date_picker') {
- return $value;
- }
- if (!str_contains($field['wrapper']['class'], $acf_date_class)) {
- return $value;
- }
-
- $acf_date = Fbpatch::get_acf_date($post_id, $field['key']);
- if ($acf_date === false) {
- return $value;
- }
-
- return $acf_date;
-}
-add_filter('acf/load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
-//add_filter('acf/pre_load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
+//function try_get_acf_date($value, $post_id, $field) {
+// $acf_date_class = Fbpatch::ACF_DATE_CLASS;
+// if ($field['type'] !== 'date_picker') {
+// return $value;
+// }
+// if (!str_contains($field['wrapper']['class'], $acf_date_class)) {
+// return $value;
+// }
+//
+// $acf_date = Fbpatch::get_acf_date($post_id, $field['key']);
+// if ($acf_date === false) {
+// return $value;
+// }
+//
+// return $acf_date;
+//}
+//add_filter('acf/load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
+////add_filter('acf/pre_load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
@@ -98,7 +98,10 @@ function add_form_builder_dates_patch() {
}
add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_dates_patch', 22);
-
+function view_date_post($form_id, $post_array) {
+ error_log("post_array: " . json_encode($post_array));
+}
+add_action('df_before_insert_post', __NAMESPACE__.'\view_date_post', 10, 2);
@@ -112,67 +115,67 @@ add_action('wp_enqueue_scripts', __NAMESPACE__.'\add_form_builder_dates_patch',
* -> 845 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php
*
*/
-function process_form_acf_dates($form_id, $post_array) {
- $acf_field_start = 'acf_date_hidden_for_';
- $acf_date_fields = \FBPATCH\array_has_keys_starting_with($acf_field_start, $post_array);
- if (empty($acf_date_fields)) {
- return;
- }
-
- foreach ($acf_date_fields as $field) {
- $acf_date = $post_array[$field];
- $acf_field = substr($field, strlen($acf_field_start));
- $new_date_text = $post_array['meta_input'][$acf_field];
- $acf_key = $post_array['meta_input']['_'.$acf_field];
- \FBPATCH\add_date_to_acf_object_class($acf_key, $acf_date);
- Fbpatch::update_acf_date($post_array['ID'], $acf_key, $acf_date);
- }
-}
-add_action('df_before_insert_post', __NAMESPACE__.'\process_form_acf_dates', 10, 2);
-
-
-/*
-* to update a field object (so, globally)
-* using `acf_update_field`
-* -> 980 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php
-*
-*/
-function add_date_to_acf_object_class($acf_id) {
- $field = get_field_object($acf_id);
- $field_class = $field['wrapper']['class'];
- $field_classes = explode(' ', $field_class);
- $class = Fbpatch::ACF_DATE_CLASS;
-
- $field_classes = array_filter($field_classes, function($value) {
- $class = Fbpatch::ACF_DATE_CLASS;
- if (strpos($value, $class) !== 0) {
- return $value;
- }
- });
-
- $field_classes[] = $class;
- $implode_class = implode(' ', $field_classes);
- $field['wrapper']['class'] = $implode_class;
- acf_update_field($field);
-}
-
-
-
-
-
-/*
-* here i use it to check if there are hidden field for acf dates
-*
-*/
-function array_has_keys_starting_with($needle, &$haystack) {
- $keys = array();
- foreach ($haystack as $key => $value) {
- if (strpos($key, $needle) === 0) {
- $keys[] = $key;
- }
- }
- return $keys;
-}
+//function process_form_acf_dates($form_id, $post_array) {
+// $acf_field_start = 'acf_date_hidden_for_';
+// $acf_date_fields = \FBPATCH\array_has_keys_starting_with($acf_field_start, $post_array);
+// if (empty($acf_date_fields)) {
+// return;
+// }
+//
+// foreach ($acf_date_fields as $field) {
+// $acf_date = $post_array[$field];
+// $acf_field = substr($field, strlen($acf_field_start));
+// $new_date_text = $post_array['meta_input'][$acf_field];
+// $acf_key = $post_array['meta_input']['_'.$acf_field];
+// \FBPATCH\add_date_to_acf_object_class($acf_key, $acf_date);
+// Fbpatch::update_acf_date($post_array['ID'], $acf_key, $acf_date);
+// }
+//}
+//add_action('df_before_insert_post', __NAMESPACE__.'\process_form_acf_dates', 10, 2);
+//
+//
+///*
+//* to update a field object (so, globally)
+//* using `acf_update_field`
+//* -> 980 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php
+//*
+//*/
+//function add_date_to_acf_object_class($acf_id) {
+// $field = get_field_object($acf_id);
+// $field_class = $field['wrapper']['class'];
+// $field_classes = explode(' ', $field_class);
+// $class = Fbpatch::ACF_DATE_CLASS;
+//
+// $field_classes = array_filter($field_classes, function($value) {
+// $class = Fbpatch::ACF_DATE_CLASS;
+// if (strpos($value, $class) !== 0) {
+// return $value;
+// }
+// });
+//
+// $field_classes[] = $class;
+// $implode_class = implode(' ', $field_classes);
+// $field['wrapper']['class'] = $implode_class;
+// acf_update_field($field);
+//}
+//
+//
+//
+//
+//
+///*
+//* here i use it to check if there are hidden field for acf dates
+//*
+//*/
+//function array_has_keys_starting_with($needle, &$haystack) {
+// $keys = array();
+// foreach ($haystack as $key => $value) {
+// if (strpos($key, $needle) === 0) {
+// $keys[] = $key;
+// }
+// }
+// return $keys;
+//}