$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>block editor - DateTimePicker script and style missing?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

block editor - DateTimePicker script and style missing?

matteradmin17PV0评论

I have a DateTimePicker Component in my Gutenberg Block. It seems, he's not correctly integrated :

  • some styles are missing
  • the zero of "05" minutes in the TextControl doesn't appear.

Is there anything I forgot ? How can I change this ?

Here is my index.js :

const {
  registerBlockType
} = wp.blocks;

import edit from './edit';
import './editor.scss';

registerBlockType('pcfestival/date', {
  title: 'Date',
  category: 'pcfestival',

  attributes: {
    date: {
      type: 'string'
    },
  },
  edit,
  save() {
    return null;
  }
});

my edit.js :

const {
  Component,
  Fragment
} = wp.element;
const { DateTimePicker, TextControl } = wpponents;
const { __experimentalGetSettings } = wp.date;
const { InspectorControls } = wp.editor;
const { withState } = wppose;

class EditDateBlock extends Component {
  constructor() {
    super(...arguments);
  }

  render() {

    const {
      attributes : {
        date
      },
      setAttributes,
      className
    } = this.props;

    const settings = __experimentalGetSettings();

    return (
      <Fragment>
        <div className={className}>
          <DateTimePicker
            currentDate={ date }
            onChange={ ( date ) => setAttributes( { date } ) }
            locale={ settings.l10n.locale }
            is12Hour={ true }
          />
        </div>
      </Fragment>
    );
  }
}

export default EditDateBlock;

and finally my plugin who enqueue scripts :

<?php
/*
Plugin Name: PCFestival
*/

defined('ABSPATH') || exit;

if ( ! class_exists('PCFestival')) {

  class PCFestival {
    protected static $instance = null;
    public static $version = 1.0;

    public static function run() {
      if( is_null(self::$instance) ) {
        self::$instance = new self();
      }
    }

    protected function __construct() {
      add_action('enqueue_block_editor_assets', array($this, 'enqueue_block_editor_assets'));
    }

    public function enqueue_block_editor_assets() {
      wp_enqueue_script(
        'pcfestival-editor',
        plugins_url('assets/blocks.editor.js', __FILE__),
        array('wp-blocks', 'wp-element', 'wp-editor', 'wp-date', 'wp-data'),
        self::$version,
        true
      );

      wp_enqueue_style(
        'pcfestival-editor',
        plugins_url('assets/blocks.editor.css', __FILE__),
        array(), // is there anything missing ?
        self::$version
      );
    }
  }

}

PCFestival::run();

a capture of the TimeDateControl

Post a comment

comment list (0)

  1. No comments so far