angular-bootstrap-slider icon indicating copy to clipboard operation
angular-bootstrap-slider copied to clipboard

no such method 'setValue' for slider widget instance

Open hmillet opened this issue 9 years ago • 18 comments

Hi,

I'm trying to use this durective in my application, but no way. I always have an "no such method 'setValue' for slider widget instance" Error, and my DOM is not like the one in your test page :

<div slider-id="mySlider" ng-model="slider.sliderValue" value="10" min="5" max="100" step="5" range="false" precision="2" reversed="false" orientation="horizontal" handle="round" enabled="true" ng-disabled="false" naturalarrowkeys="false" class="ng-isolate-scope ng-valid">
  <input class="slider-input ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all" type="text" aria-disabled="false"></input>
</div>

Has someone an idea on my trouble ?

hmillet avatar May 16 '15 22:05 hmillet

No idea; can you make a plunker that simulates your environment better?

seiyria avatar May 16 '15 23:05 seiyria

Difficult... it's a big app with so many libraries :-(

hmillet avatar May 16 '15 23:05 hmillet

Sorry, without knowing specifically what's going wrong, it's hard to debug an issue.

seiyria avatar May 16 '15 23:05 seiyria

I understand that ... I will still "fight" to understand my trouble... until I can make a plunker

hmillet avatar May 16 '15 23:05 hmillet

I got it.

This does not work when include jquery-ui. That's annoying. Here is my plunker.

http://plnkr.co/edit/hO421vl7G1nHAfCtvclK?p=preview

When you remove the jquery-ui script, all is fine... except that I don't understand why my initial value is not set

Thanks for Help

hmillet avatar May 17 '15 08:05 hmillet

There is an issue about this on the bootstrap-slider project : https://github.com/seiyria/bootstrap-slider/issues/250

An answer was find here for the bootstrap-slider : http://stackoverflow.com/questions/26691018/using-bootstrap-slider-with-jquery-ui

It says : use bootstrapSlider() function in order ti initialize the bootstrap-slider, in replacement of slider()

Maybe this directive can consider this...

hmillet avatar May 17 '15 08:05 hmillet

If you'd like to submit a PR that adds a new attribute no-conflict then I'd take it!

seiyria avatar May 17 '15 15:05 seiyria

What about using the same test than the original bootstrap-slider component, instead of a new no-conflict attribute ?

if($) {
  var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider';
  $.bridget(namespace, Slider);
}

hmillet avatar May 17 '15 20:05 hmillet

That'd be fine also.

seiyria avatar May 17 '15 20:05 seiyria

Well, I can't achieve in making this works.

Adding jQuery-UI, we must use mySlider.bootstrapSlider() instead of mySlider.slider() (information from seiyria/bootstrap-slider)

Replacing then the 6 occurences of slider with bootstrapSlider in the directive script make a new errors occurs, that I cannot understand :

TypeError: Cannot read property 'removeChild' of null
    at Slider.destroy (http://abs.dev.hmillet.com/bower_components/seiyria-bootstrap-slider/js/bootstrap-slider.js:780:31)
    at $.fn.(anonymous function) [as bootstrapSlider] (http://abs.dev.hmillet.com/bower_components/seiyria-bootstrap-slider/js/bootstrap-slider.js:134:50)
    at initSlider (http://abs.dev.hmillet.com/slider.js:113:32)
    at Object.fn (http://abs.dev.hmillet.com/slider.js:187:25)

In the destroy method in bootstrap-slider.js, this.sliderElem.parentNode is null :-(

            destroy: function(){
                // Remove event handlers on slider elements
                this._removeSliderEventHandlers();

                // Remove the slider from the DOM
                this.sliderElem.parentNode.removeChild(this.sliderElem);
                /* Show original <input> element */
                this.element.style.display = "";

                // Clear out custom event bindings
                this._cleanUpEventCallbacksMap();

                // Remove data values
                this.element.removeAttribute("data");

                // Remove JQuery handlers/data
                if($) {
                    this._unbindJQueryEventHandlers();
                    this.$element.removeData('slider');
                }
            },

if someone has any idea...

hmillet avatar May 23 '15 14:05 hmillet

Are you using the right version of the library with the directive?

seiyria avatar May 23 '15 19:05 seiyria

Think so.

Clone the project, run bower install...

hmillet avatar May 23 '15 19:05 hmillet

Just checking. I don't know, it should not matter which function you use. That said, I can't claim to understand how bridget works; it COULD be a byproduct of this library using the jQuery wrapper instead of using the vanilla JS style. Perhaps, the PR would remove the jQuery aspect and instead use that vanilla JS constructor?

seiyria avatar May 23 '15 19:05 seiyria

The same error occurs in the following (slider.js - line 178):

// deregister ngModel watcher to prevent memory leaks if (angular.isFunction(ngModelDeregisterFn)) ngModelDeregisterFn(); ngModelDeregisterFn = $scope.$watch('ngModel', function (value) { slider.slider('setValue', value); }, true);

namwkim avatar Jun 09 '15 00:06 namwkim

@namwkim : Are you using jQuery-UI ?

hmillet avatar Jun 09 '15 07:06 hmillet

Yea I am using jQuery-UI. As far as I know it worked with jQuery-ui before.

I am wondering if this problem occurs with recent updates?.

Here is a working version if you want: Site: https://study.namwkim.org/bubble/admin# Source: view-source:https://study.namwkim.org/bubble/admin#

namwkim avatar Jun 09 '15 18:06 namwkim

It's possible that jquery UIs slider is interfering with it, as it has in the past.

seiyria avatar Jun 09 '15 19:06 seiyria

@namwkim The versions you've linked to fix the issue. Where are they from? Thanks btw!!

fergalmoran avatar Aug 21 '15 20:08 fergalmoran