Semantic-ui: [Button] should toggle with state function

Created on 6 Apr 2018  路  12Comments  路  Source: Semantic-Org/Semantic-UI

It seems that toggle button is broken since 2.3.1 version,
all was good for toggle buttons in 2.3.0

Steps

<a class="ui toggle button">Toggle</a>
<script>$(".ui.button.toggle").state();</script>

Expected Result

a toggle button...

Actual Result

Uncaught TypeError: $(...).state is not a function
    at HTMLDocument.<anonymous>

Version

Semantic ui 2.3.1 (cdnjs)
jQuery 3.3.1

Testcase

https://jsfiddle.net/jcheron/n90gcwjz/2/

Note

Version 2.3.1 available at https://semantic-ui.com/dist/semantic.min.js works, while cdn (cdnjs or cdn.jsdelivr.net) does not work.

The files are different!

Confirmed Bug

Most helpful comment

In case the reason has not been resolved and for those who want an interim patch - this is because the 2.3.1 package does not have state.js and state.min.js files - just a build issue. I copied the files from 2.3.0 as a temp fix and yay all sorted.

All 12 comments

In case the reason has not been resolved and for those who want an interim patch - this is because the 2.3.1 package does not have state.js and state.min.js files - just a build issue. I copied the files from 2.3.0 as a temp fix and yay all sorted.

The 2.3.2 package still does not include the state module which has disappeared since 2.3.1

This is unfortunate because semantic-ui is unusable via all cdns.
It is necessary to add the latest available version of state.js manually:

<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.0/components/state.min.js"></script>

Hitting this too; would love a real solution.

Having this problem as well.

+1

+1

+1

This is still an issue with 2.4.1, starting to feel like this project might be dead. I can not believe no one else uses toggle buttons and it has been left unresolved for this long.

So since there i no longer a state.js in the components even I am not sure what there plan is for the future of the toggle button. I was able to come up with the following temp solution at least until they fix it or I find another component library.

Remove the startup call to

$(".ui.button.toggle").state();

doing this will not allow toggle buttons to work by default anymore but you can still do something like

//Button Code
$('#btnToggleButton').click(function () {
$('#btnToggleButton').removeClass('active');
//button press stuff, setting some variable that stores if it should be toggled or not
if (shouldBeToggled) {
$('#btnToggleButton').addClass('active');
}
});

I hope they fix this in the next version but if not I can at least still use the component for now using this code.

The state components is not also available on the 2.4.2 version

The state components is not also available on the 2.4.2 version

@whoami213 Look at my comment above. The active community fork https://fomantic-ui.com already re-implemented the state behavior two years ago in 2.5.0 as it was removed in SUI just because of missing documentation.
The unlinked and incomplete docs are here https://fomantic-ui.com/behaviors/state.html
See https://jsfiddle.net/L76mq0vo/

Was this page helpful?
0 / 5 - 0 ratings