Giter VIP home page Giter VIP logo

Comments (13)

elliotcondon avatar elliotcondon commented on July 24, 2024 2

Hi @ffranchina

Thanks for the bug report and PR.
Yes, it looks like the date / time picker fields don't respect the 'disabled', 'readonly' or 'required' attributes. I will do some testing and add this into the next version.

Thanks
Elliot

from acf.

elliotcondon avatar elliotcondon commented on July 24, 2024 2

Hi guys.

Thanks for prompting me to look into this again.
I've had another look and implemented a fix.

To help test, please edit the file "includes/fields/class-acf-field-date_picker.php" and change the render_field() function on line 92 to:

	function render_field( $field ) {
		
		// vars
		$hidden_value = '';
		$display_value = '';
		
		// format value
		if( $field['value'] ) {
			$hidden_value = acf_format_date( $field['value'], 'Ymd' );
			$display_value = acf_format_date( $field['value'], $field['display_format'] );
		}
		
		// elements
		$div = array(
			'class'					=> 'acf-date-picker acf-input-wrap',
			'data-date_format'		=> acf_convert_date_to_js($field['display_format']),
			'data-first_day'		=> $field['first_day'],
		);
		$hidden_input = array(
			'id'					=> $field['id'],
			'name'					=> $field['name'],
			'value'					=> $hidden_value,
		);
		$text_input = array(
			'class' 				=> 'input',
			'value'					=> $display_value,
		);
		
		// special attributes
		foreach( array( 'readonly', 'disabled', 'required' ) as $k ) {
			if( !empty($field[ $k ]) ) {
				$hidden_input[ $k ] = $text_input[ $k ] = $k;
			}
		}
		
		// save_format - compatibility with ACF < 5.0.0
		if( !empty($field['save_format']) ) {
			
			// add custom JS save format
			$div['data-save_format'] = $field['save_format'];
			
			// revert hidden input value to raw DB value
			$hidden_input['value'] = $field['value'];
			
			// remove formatted value (will do this via JS)
			$text_input['value'] = '';
		}
		
		// html
		?>
		<div <?php acf_esc_attr_e( $div ); ?>>
			<?php acf_hidden_input( $hidden_input ); ?>
			<?php acf_text_input( $text_input ); ?>
		</div>
		<?php
	}

Please let me know how you go with this :)

from acf.

jornhenkes avatar jornhenkes commented on July 24, 2024 2

@elliotcondon If this can be added to the plugin, that would be great! I was looking for exactly this fix.

from acf.

Bnjis avatar Bnjis commented on July 24, 2024 2

@elliotcondon no problèm ;)

I try with this code :

foreach( array( 'readonly', 'disabled', 'required' ) as $k ) {
	if( !empty($field[ $k ]) ) {
		$hidden_input[ $k ] = $k;
	}
}

just delete the $text_input[ $k ] in the foreach and it's work fine for me.

If i can help i'm here ;)

from acf.

beezischillin avatar beezischillin commented on July 24, 2024 2

@Bnjis, your solution seems to have fixed the issue for me temporarily! I'm not sure if it causes any issues but thank you for this! You saved my hide before my client would've noticed this.

from acf.

ffranchina avatar ffranchina commented on July 24, 2024 1

Great! Thank you :)

Have a nice day!
Francesco

from acf.

elliotcondon avatar elliotcondon commented on July 24, 2024 1

Hi @Bnjis

Thanks for the bug report. I have just tested and can confirm the same issue.
I will work on a fix for this today

from acf.

Bnjis avatar Bnjis commented on July 24, 2024 1

@beezischillin Your welcom ;)

Yes i don't know too for other issues. I think the dev team will fix it soon.
I do an other fix without update plugin code with javascipt if you want :

acf.add_action("load", function($el) {
  var $form = $("ACFFORMNAME");
  $form.find(".acf-input input.hasDatepicker").attr('required', null)
}

from acf.

elliotcondon avatar elliotcondon commented on July 24, 2024 1

@FriendlyWP Thanks. Version 5.8.0-beta3 is now a little behind the latest 5.7.9 and 5.7.10 (planfor today) versions. The next 5.8.0 beta will definitely have this fixed.

from acf.

christianmagill avatar christianmagill commented on July 24, 2024

Did this ever get incorporated?

from acf.

Bnjis avatar Bnjis commented on July 24, 2024

Hi @elliotcondon i think you add a bug in this issue,

When you do this :

// special attributes
foreach( array( 'readonly', 'disabled', 'required' ) as $k ) {
    if( !empty($field[ $k ]) ) {
        $hidden_input[ $k ] = $text_input[ $k ] = $k;
    }
}

You add a "requiered" attribute to a text input.
If this text input is "display none" by a repeater fields or a conditionnal display, you will have an error when you try to save post.

The browser will try to focus in the field but he can not. in this case you need to add a "novalidate" attribute on the form or remove the "requiered" on the text input.

We try and we got this screen :

acf_bug

from acf.

FriendlyWP avatar FriendlyWP commented on July 24, 2024

I can confirm this is still happening in 5.8.0-beta3. Required text field inside a Repeater (inside a Flexible Content field set) throws the error, making it impossible to save/publish the page if that FC field wasn't selected /used / filled-out.

from acf.

DjMorgul avatar DjMorgul commented on July 24, 2024

Please, beware this issue happens also for date_time_picker fields, and the solution is the same one that was applied to date_picker fields on version 5.8.0. In version 5.8.0, it's working on date_picker fields, but not on date_time_picker fields.

And the same goes for fields of type user, they can't be disabled. But with these, it can't be fixed in the same way as the date pickers.

from acf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.