• Resolved anoktear

    (@anoktear)


    The floating labels are not being triggered. It’s working on the backoffice if I press to see Material Blocks.

    <form class="mdc-form-field contactForm" method="POST" action="https://script.google.com/macros/s/testing">
    	<div class="mdc-form-field form-elements">
    	<label class="mdc-text-field mdc-text-field--outlined">
    	<span class="mdc-notched-outline">
    	<span class="mdc-notched-outline__leading"></span>
    	<span class="mdc-notched-outline__notch">
    	<span class="mdc-floating-label" id="full-name">Full Name</span>
    	</span>
    	<span class="mdc-notched-outline__trailing"></span>
    	</span>
    	<input type="text" class="mdc-text-field__input" aria-labelledby="full-name" required>
    	</label>
    	</div>
    </form>

    I’m testing locally with a child theme of GeneratePress on WordPress 5.8.

    It’s working if I activate the included Material Design Theme. However, I want to use the functionality without the Material theme.

    GeneratePress is one of the most popular themes. What do I need to do?

    • This topic was modified 3 years, 7 months ago by anoktear. Reason: format
    • This topic was modified 3 years, 7 months ago by anoktear. Reason: format
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter anoktear

    (@anoktear)

    I checked what the Material theme was doing and copied the Material theme front-end.js into the GeneratePress child theme, enqueued the script on functions.php and it works.

    Questions: Is the JS file provided by the Material plugin not enough without using the Material theme? Or was it because I have the form in a plugin? Food for thought.

    Hi @anoktear

    I have just been looking at this and the plugin should have added the front-end.js to the footer in your theme

    can you check you are running wp_footer in your child theme?

    maybe try loading the parent theme on it own

    Paul

    Thread Starter anoktear

    (@anoktear)

    Hello @pbearne

    It’s a strange behaviour, front-end.js is added to the footer of the child theme using the plugin. However, floating labels won’t work.

    If I turn off the plugin and enqueue front-end.js and the quickstart CDN in functions.php of the child theme, then it works fine.

    functionmaterial_enqueue_style() {
    
    wp_enqueue_style( 'material-style', 'https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css');
    
    wp_enqueue_script( 'material-script', 'https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js', array(), null, true);
    
    wp_enqueue_script( 'material-front-end', get_stylesheet_directory_uri().'/assets/js/front-end.js', array(), null, true);
    
    }
    
    add_action( 'wp_enqueue_scripts', 'material_enqueue_style' )

    Conclusion, floating labels won’t work just by turning on the material plugin. I have this same behaviour in all default WordPress themes. Attention that my form is inside a custom plugin, is this relevant?

    Thread Starter anoktear

    (@anoktear)

    Update: Some more tests by using the Material plugin. I added a material form to a page, it works. However, when adding the form to Widgets, it won’t apply the floating labels. So the problem is front-end.js not being applied inside widgets?

    Plugin Support Utkarsh

    (@utkarshpatel)

    Hello @anoktear,

    Material plugin doesn’t initiate all the custom labels and only handles the contact form.

    Here is the code: https://github.com/material-components/material-design-for-wordpress/blob/501a7d4dc0a412d46b81602d6648e39096a977ca/plugin/assets/src/front-end/contact-form.js#L47-L54

    You can add your custom selector in custom JS and initiate, that should work.

    Theme handles initializing that, that’s why it works when you inject JS from theme – https://github.com/material-components/material-design-for-wordpress/blob/501a7d4dc0a412d46b81602d6648e39096a977ca/theme/assets/src/front-end/components/textfield.js#L20-L29.

    We will check internally and see if we would handle initializing it from plugin if theme isn’t active.

    Cheers!
    Utkarsh Patel

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Floating labels not working’ is closed to new replies.