Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

javascript - Repost/ asking again. Change event in Kartik's bootstrap-slider extension for Yii2

I asked that question today and the user gave me best answer, but it seems that its not working. Maybe its all because i use not raw Bootstrap-slider.js but Kartik's extension. So here is what i do:

<div class="col-md-4">
    <input  type="text" 
                class="form-control" 
                id="test"
                placeholder="50000">
        <?php echo Slider::widget([
                'name'=> 'test-bi',
            'sliderColor'=> Slider::TYPE_GREY,
            'pluginEvents' => [
                 'slide' => "function(slideEvt) {
                        $('#test').val(slideEvt.value); 
                    }",
            ],
            'pluginOptions' => [
                'min'=>50000,
            'max'=>200000,
            'step'=>1,
            'tooltip'=>'hide',
            ],
            ]);
        ?>
    </div>
</div>

It looks like:enter image description here As you can see slide trigger works nice, but i also trying to update or refresh the slider if the value inside an input is changed. The answer that i got not working for

$this->registerJs(
    "$('#test').on('change',function(){
        $('#w17-slider').slider('setValue',$(this).val());
    })",
    yiiwebview::POS_LOAD);

May be its all because i use extension? Is there is the way to use change trigger inside <?php widget ?> ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should always keep your console or developer bar open when working with javascript, you never know when something conflicts with the other.

You need to use parseInt() to pass a value to the setValue function of the slider, it is interpreting it as text, otherwise, it throws

Uncaught Error: Invalid input value '1' passed in

if you are getting the same error as above in your console when you type in the text box, then you need to change the code to the following

$this->registerJs(
    "$('#test').on('input',function(){
        $('#w17-slider').slider('setValue',parseInt($(this).val()));
    })",
    yiiwebview::POS_READY);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...