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
(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 ?
Maybe try this:
Fix:
Changed the enqued script to jquery only then made
settings without sanitize callback (previously used sanitize intvl like wp says)
Something like this.