xpepermint / angular-ui-switch

On/off switch button for AngularJS. DEPRECATED!
278 stars 127 forks source link

Disabled not working #33

Open celsomtrindade opened 8 years ago

celsomtrindade commented 8 years ago

The switch with property 'disabled=true' is not working.

I checked my console and the input didn't had the disabled=true set, so i was able to interact with it anyway.

I added this line and it worked:

html += attrs.disabled ? ' disabled="' + attrs.disabled +'"' : '';

This is the overall input code:

html += '<input type="checkbox"';
html += attrs.id ? ' id="' + attrs.id + '"' : '';
html += attrs.name ? ' name="' + attrs.name + '"' : '';
html += attrs.ngModel ? ' ng-model="' + attrs.ngModel + '"' : '';
html += attrs.disabled ? ' disabled="' + attrs.disabled +'"' : '';
html += ' style="display:none" />';

The code i was using was based on the example provided, like this:

<switch name="testing" ng-model="testing" disabled="true"></switch>

After doing this, everything works fine, even with disabled true/false.

ido567 commented 8 years ago

There is a way to make it work with ng-disabled?

celsomtrindade commented 8 years ago

@ido567 if you change the original file like I did, you can use it normally.

ido567 commented 8 years ago

That's the only way, I really try to avoid that

celsomtrindade commented 8 years ago

@ido567 We'll have to wait to see if they have other solution, or other method. I didn't found any other way to solve this. Or maybe I'm missing something.

nicokaen commented 8 years ago

I found a workaround, using data-disabled:

<switch name="testing" ng-model="testing" data-disabled="isDisabled"></switch>

vpgayakwad commented 7 years ago

How can we set it to true or false dynamically on some conditions?