ngx-slider icon indicating copy to clipboard operation
ngx-slider copied to clipboard

Reactive form disable support

Open dmoojunk opened this issue 4 years ago • 7 comments

Currently Im having fun trying to integrate this into a reactive form that uses form groups - and toggles them on and off with enable() and disable(). This just recursively calls the same on the child controls.

Interestingly, the styling does change, however they are still editable if you click. Here is a small demo - https://stackblitz.com/edit/angular-ivy-cstipf?file=src/app/hello.component.ts

Wondered if this could be supported, or perhaps a workaround suggestion?

Thanks for your library and time!

dmoojunk avatar Nov 18 '20 20:11 dmoojunk

Anything on this issue? I am having the same problem. I disable the control but it keeps being editable in the form.

mariocalin avatar Feb 12 '21 12:02 mariocalin

I fixed this issue and will make a pull request for it next week (I'd like to add some e2e tests for it first).

hakla avatar Oct 13 '21 12:10 hakla

We could really use a fix about now.

@hakla is there a workaround we can use as consumers?

One half-workaround is to conditionally add a class that adds pointer-events: none; but this only disables mouse input changes, not keyboard input.

SarcevicAntonio avatar Nov 16 '21 10:11 SarcevicAntonio

Same issue, I was trying to dynamically change the options dictionary that gets set into the slider. There's an option disabled. But changing it hotly doesn't update the component.

The workaround I am using is to use @ViewChild and select the component. Then calling setDisabledState(trueOrFalse).

A TypeScript problem is that the module does not export the SliderComponent, it only exports the NgxSliderModule, so I cannot tell it is going to be a SliderComponent, instead I have to turn off TypeScript resolution and use the infamous any:

@Component({
  selector: 'mycomp',
  template: `<button (click)="disableSlider()">Disable Slider</button><ngx-slider #mySlider ...></ngx-slider>`
  ...
})
export class MyCompComponent {
    @ViewChild('mySlider') sliderComponent!: any;

    disableSlider() {
      this.sliderComponent?.setDisabledState(true);
    }
    
}

I created two issues and I am happy to work on them if I get an OK from the mantainers of this project:

eulersson avatar Nov 19 '21 16:11 eulersson

This works, but only makes it styled like it's disabled. You can still click and drag the slider 👀

SarcevicAntonio avatar Nov 23 '21 12:11 SarcevicAntonio

This works, but only makes it styled like it's disabled. You can still click and drag the slider 👀

That is true 😢

eulersson avatar Nov 23 '21 16:11 eulersson

@SarcevicAntonio Sorry for the late reply, I did not find the time to create the e2e tests as I wanted. For our project, I created an npm package that we are using until this is merged into ngx-slider. You can use this as well and switch back to the official slider after it is merged. It is available under the name @hakla/ngx-slider.

hakla avatar Nov 25 '21 09:11 hakla