Invalid value error on Range Input WP Customizer

Range input value not working in wp customizer.
This is my class for the wordpress customizer controll and bellow that is the js code.

<?php
    // Range Control Wwith Selected Value Indicator
    class WP_Customize_Range_Control extends WP_Customize_Control
    {
        public $type = 'custom_range';
        public function enqueue()
        {
            wp_enqueue_script(
                'cs-range-control',
                BLOCKS_URL . '/lib/js/controls.js',
                array('jquery-ui-slider'),
                false,
                true
            );
        }
        public function render_content()
        {
            ?>
            <label>
                <?php if ( ! empty( $this->label )) : ?>
                    <span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
                <?php endif; ?>
                <div class="cs-range-value"><?php echo esc_attr($this->value()); ?></div>
                <input data-input-type="range" type="range" <?php $this->input_attrs(); ?> value="<?php echo esc_attr($this->value()); ?>" <?php $this->link(); ?> />
                <?php if ( ! empty( $this->description )) : ?>
                    <span class="description customize-control-description"><?php echo $this->description; ?></span>
                <?php endif; ?>
            </label>
            <?php
        }
    }

// This is the JS

Read More
(function ($) {
    $(document).ready(function ($) {
        $('input[data-input-type="range"]').on('change', function () {
            var val = $(this).val();
            $(this).prev('.cs-range-value').html(val);
            $(this).val(val);
        });
    })
})(jQuery);

When i change the value of the slider in WP Customizer i get an error with Invalid value. Why is happening and how do i fix it ?

Related posts

Leave a Reply

2 comments

  1. Fix:
    Changed the enqued script to jquery only then made
    settings without sanitize callback (previously used sanitize intvl like wp says)
    Something like this.

    $wp_customize->add_setting( 'wca_header_opacity', array(
        'default' => '',
        'transport' => 'postMessage',
        ) );
    
        $wp_customize->add_control(
        new WP_Customize_Range_Control(
            $wp_customize,
            'header_opacity',
            array(
                'label'       => __('Header Opacity When Fixed'),
                'section'     => 'wca_header_section_design',
                'settings'    => 'wca_header_opacity',
                'context'    => 'wca_header_opacity',
                'description' => __('Set transparency for header when is fixed for an awesome effect !'),
                'input_attrs' => array(
                    'min' => 0,
                    'max' => 1,
                    'step' => 'any',
                ),
                'priority'   => 10
            )
        )
        );