cgarvis / angular-toggle-switch

AngularJS Toggle Switch
http://cgarvis.github.io/angular-toggle-switch
MIT License
160 stars 124 forks source link

Add enabled & editable properties #14

Closed mmaestri closed 10 years ago

mmaestri commented 10 years ago

Hi I've stumbled upon this and it was exactly what I was looking for. I made a few changes that you might like to check. It just adds two attributes: enabled and editable.

enabled: allows to disable the toggle and adds a 'disabled' class to reflect its status. editable: it only disables the toggle.

Sorry if I'm missing some 'github etiquette', I'm new to this.

Thanks for your work

mgmaestri

cgarvis commented 10 years ago

Why would you want to "disable" the toggle without adding the disabled class?

mmaestri commented 10 years ago

Because I needed two behaviours

Block edit, maintain value -> editable. I have a set of toggles which reflects some user config. It should not be editable unless the user presses some button.

Block edit, set value to false -> disabled. Same set of toggles, some are enabled or disabled according to other toggle values. Here I needed somehow to show the user that the control is actually disabled. Hence, I added the disabled class.

cgarvis commented 10 years ago

Sounds like you would just be better served by adding a separate class on the toggle that doesn't "grey out" the toggle.

<toggle-switch class="no-disable"></toggle-switch>
cgarvis commented 10 years ago

@mmaestri If you remove editable, change enable to disable, and use the attr.$observe, I'll merge this in today. We can work out the editable feature in another pull request.

mmaestri commented 10 years ago

Done. I'm on the office right now and don't have much more time, but I've made a few tests and it seems to work well. Sorry about indentation...I'm used to tabs, if there's a problem with that I'll change to whatever you like.

Thanks

cgarvis commented 10 years ago

AngularJS uses 2 spaces tabs. So i'm just following suit.

mmaestri commented 10 years ago

@cgarvis Done. Let me know if there's something else to do.

Thanks

cgarvis commented 10 years ago

@mmaestri tab indent is back