contao-thememanager/ctm-placeholder-label
Installation
composer require contao-thememanager/ctm-placeholder-label
Ensure the package is enabled in config/packages.php or via Contao's extension manager.
ThemeManager Configuration
$pl-input-top-offset, $pl-textarea-top-offset, $pl-label-filled-top-offset, $pl-label-filled-font-size) to match your design requirements.CSS Integration
_placeholderlabel.css after _theme.css (order matters).layout.css:
/* ... other styles ... */
@import '_theme.css';
@import '_placeholderlabel.css';
JavaScript Integration
js_ctm_placeholderlabel.First Use Case
Add a form field (e.g., <input type="text" name="email" placeholder="Your Email">) in a template. The placeholder will animate when the field is filled, and the label will shift upward based on your configured offsets.
Form Field Styling Use the package to replace static placeholders with animated labels. Example:
<form>
<input type="text" name="username" class="form-control">
<label for="username">Username</label>
</form>
Dynamic Configuration Override default offsets per form type (e.g., textareas vs. inputs):
/* In your theme's CSS */
$pl-textarea-top-offset: 12px;
$pl-label-filled-font-size: 14px;
Excluding Forms
Disable the effect for specific forms by adding the pl-none class:
<form class="pl-none">
<!-- Placeholder label disabled -->
</form>
Custom JavaScript
Extend or override the default behavior by modifying js_ctm_placeholderlabel:
// Override the default options
window.ctmPlaceholderLabelConfig = {
selector: '.custom-form', // Target specific forms
excludeClass: 'no-animation' // Custom exclusion class
};
Integration with Contao Forms For Contao-managed forms, ensure the package’s JS/CSS is included in the Form Layout settings:
_placeholderlabel.css and js_ctm_placeholderlabel.Conditional Label Animation
Use Contao’s enctype or custom classes to toggle animations:
<input type="text" name="password" class="pl-animate-on-focus">
Extend the JS to handle this:
window.ctmPlaceholderLabelConfig = {
selector: 'form',
customTriggers: ['focus', 'input'] // Add custom events
};
Theme-Specific Overrides Create a child theme to override the package’s CSS/JS without modifying the parent theme’s settings.
Accessibility
Ensure labels remain accessible by pairing with aria-label or aria-labelledby:
<input type="text" name="search" aria-labelledby="search-label">
<label id="search-label">Search</label>
CSS Order Dependency
_placeholderlabel.css is loaded before _theme.css._theme.css → _placeholderlabel.css.JavaScript Conflicts
js_ctm_placeholderlabel, the script fails silently.Form Field Selector Mismatch
selector: 'form' may target unintended forms (e.g., Contao backend forms)..frontend-form) or use the excludeClass to opt out.Custom CSS Variable Overrides
$pl-* variables in a child theme may not apply if the parent theme’s CSS is cached.contao:clear-cache) or use !important sparingly.Textarea Handling
$pl-textarea-top-offset or add custom CSS:
textarea.form-control {
padding-top: calc(var(--pl-textarea-top-offset) + 2px);
}
Inspect Element Use browser dev tools to check if:
--pl-input-top-offset) are applied.js_ctm_placeholderlabel) is loaded and error-free.Console Logs
Add debug logs to js_ctm_placeholderlabel to verify initialization:
console.log('PlaceholderLabel initialized for:', window.ctmPlaceholderLabelConfig.selector);
Disable Caching Temporarily disable Contao’s cache to rule out cached assets:
// config/localconfig.php
$GLOBALS['TL_CACHEDIR'] = '/tmp/contao-cache';
Custom Animations Extend the JS to support GSAP, Anime.js, or CSS transitions:
// Example: Replace default fade with slide-up
window.ctmPlaceholderLabelConfig.animation = {
enter: 'slideUp',
exit: 'slideDown'
};
Server-Side Validation Hooks Trigger label animations on form submission success/failure via Contao hooks:
// config/config.php
$GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = function() {
if (\Input::get('do') === 'save' && \Input::get('token') === \Session::get('CSRF')) {
echo '<script>document.querySelectorAll(".form-success").each(function(el) {
el.querySelector("input").dispatchEvent(new Event("input"));
});</script>';
}
};
Multi-Language Support Dynamically update labels for multilingual forms by binding to Contao’s language switcher:
document.addEventListener('languageChanged', function() {
window.ctmPlaceholderLabel.init();
});
How can I help you explore Laravel packages today?