The form examples show how to add graceful degradation so AJAX behavior can work when JavaScript is disabled. This is done with a submission button that's hidden with a CSS class.
// Since we don't know if the user has js or not, we always need to output
// this element, then hide it with with css if javascript is enabled.
$form['instrument_family_fieldset']['choose_family'] = [
'#type' => 'submit',
'#value' => $this->t('Choose'),
'#attributes' => ['class' => ['ajax-example-hide', 'ajax-example-inline']],
];
This is using a custom CSS class.
However, Drupal core already provides a CSS class for the same purpose.
/**
* For anything you want to hide on page load when JS is enabled, so
* that you can use the JS to control visibility and avoid flicker.
*/
.js .js-hide {
display: none;
}
The example should use the CSS class already defined from Drupal core, instead of using a new CSS class.
Issue fork examples-3350455
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
avpadernoComment #3
avpadernoComment #5
avpadernoComment #7
avpaderno