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

Dynamic disabling does not work with reactive forms

Open danisss9 opened this issue 1 year ago • 1 comments

import { Options as SliderOptions } from 'ngx-slider-v2'; Here are my options:

sliderOptions: SliderOptions = { 
    floor: 0,
    ceil: 100,
    showSelectionBar: true,
    hidePointerLabels: true,
    hideLimitLabels: true,
    disabled: false
  };

html <ngx-slider [options]="sliderOptions" formControlName="rxvolume"></ngx-slider>

dynamically disable/enable

disableEnableFields(disabled: boolean) {
    this.sliderOptions = Object.assign({}, this.sliderOptions, {disabled: disabled});
    disabled ? this.form.disable() : this.form.enable();
  }

This works if I don't have the formControlName on the directive. With the formControlName, it adds the [disabled]='disabled' to the DOM, and the classes show up, but I can still move the slider. The same goes in reverse. If I start with the slider options set to disabled: true. it IS disabled and I cannot move the slider, and dynamically setting disabled to false does not allow me to move the slider. Again, this only seems to be the case when I'm using formControlName. If I don't, it disables/enables the slider dynamically without issue.

Edit: This also seems to be affected because of enabling, disabling the form dynamically. When this line disabled ? this.form.disable() : this.form.enable(); is removed, the slider enables/disables as it should.

danisss9 avatar Jan 30 '24 10:01 danisss9

To answer your earlier question, the slider is not actually disabled when using a reactive form with formControlName. It does work with ngModel

mmestas avatar Jan 31 '24 14:01 mmestas