From e52d267fd3aa17e9c18029b39ab26579df0438ed Mon Sep 17 00:00:00 2001
From: Niraj Chaudhary <99162269+NirajChaudhary143@users.noreply.github.com>
Date: Thu, 5 Sep 2024 10:12:57 +0545
Subject: [PATCH] Tweak - Hidden field editable compatibility (#1327)
* Tweak - Field which are made hidden are editable
* Tweak - Hidden field also editable
* Fix phpcs
* Fix - PHPCS
---
includes/evf-core-functions.php | 13 ++++++++++++-
includes/fields/class-evf-field-hidden.php | 7 ++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/includes/evf-core-functions.php b/includes/evf-core-functions.php
index c1ca54f6f..9853d393b 100644
--- a/includes/evf-core-functions.php
+++ b/includes/evf-core-functions.php
@@ -974,6 +974,8 @@ function evf_html_attributes( $id = '', $class = array(), $datas = array(), $att
$id = trim( $id );
$parts = array();
+ $is_edit_entry = isset( $_GET['edit-entry'] ) && ! sanitize_text_field( wp_unslash( empty( $_GET['edit-entry'] ) ) ) ? true : false;
+
if ( ! empty( $id ) ) {
$id = sanitize_html_class( $id );
if ( ! empty( $id ) ) {
@@ -984,6 +986,10 @@ function evf_html_attributes( $id = '', $class = array(), $datas = array(), $att
if ( ! empty( $class ) ) {
$class = evf_sanitize_classes( $class, true );
if ( ! empty( $class ) ) {
+ // While editing hidden field should be visible.
+ if ( $is_edit_entry ) {
+ $class = str_replace( 'evf-field-hidden', '', $class );
+ }
$parts[] = 'class="' . $class . '"';
}
}
@@ -1003,7 +1009,12 @@ function evf_html_attributes( $id = '', $class = array(), $datas = array(), $att
} else {
$escaped_att = sanitize_html_class( $att );
}
- $parts[] = $escaped_att . '="' . esc_attr( $val ) . '"';
+ // While editing, fields must be visible even if they are hidden.
+ if ( 'style' == $escaped_att && $is_edit_entry ) {
+ $parts[] = 'style = "display: block"';
+ } else {
+ $parts[] = $escaped_att . '="' . esc_attr( $val ) . '"';
+ }
}
}
}
diff --git a/includes/fields/class-evf-field-hidden.php b/includes/fields/class-evf-field-hidden.php
index 98dfc2db8..7788b6be5 100644
--- a/includes/fields/class-evf-field-hidden.php
+++ b/includes/fields/class-evf-field-hidden.php
@@ -82,9 +82,14 @@ public function field_display( $field, $field_atts, $form_data ) {
// Define data.
$primary = $field['properties']['inputs']['primary'];
+ // For edit purpose.
+ $is_edit_entry = isset( $_GET['edit-entry'] ) && sanitize_text_field( wp_unslash( $_GET['edit-entry'] ) ) ? true : false;
+ $field_type = $is_edit_entry ? 'text' : 'hidden';
+
// Primary field.
printf(
- '',
+ '',
+ $field_type,
evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] )
);
}