Make forms look like your theme
What it does
This page makes WebForms forms take the look of your theme: input boxes, dropdowns, checkboxes, the Submit button and the popup window. It's the developer side of Two form styles. Everything here is settings, one script and a few CSS rules, with no template copied into the theme.
Every step was checked on a test store running WebForms 4.0.1. WebForms 4.0.2 changes none of them.
Before you start
- Access to Stores → Configuration, Content → Widgets and the form builder.
- On Hyvä, a theme whose Tailwind build contains the classes you plan to use, such as Hyvä's
form-input,form-selectandbtn. - To restyle the popup, a place in your theme for a small script or a CSS rule on every page.
Steps
Luma and Breeze
- Go to Stores → Configuration → MageMe Extensions → WebForms, expand Appearance, then Modern Field Style. In Enable Modern Field Style, select No, in Default Config or in the store view you need.
- Leave the color, variant and size of the Submit element at their defaults. A value set there is printed on the button and outranks the theme's button on Luma, Hyvä and Breeze.
- Click Save Config and refresh the cache types Magento marks as invalid.
- On Luma, open each WebForms: Button With Popup widget in Content → Widgets, add
actionto Custom Button CSS Classes and save. Without it the button that opens the popup is grey; with it it's the theme's main button.
Fields and the Submit button now take your theme's styles. The button carries action submit primary.
Hyvä
-
Do steps 1 to 3 of Luma and Breeze. The Submit button becomes
btn btn-primaryof your theme. -
The input boxes, labels and messages still use the classes of Hyvä Theme CSS Classes, whatever Enable Modern Field Style says, and their defaults draw the WebForms look. Go to Stores → Configuration → MageMe Extensions → WebForms, expand Developer, then Hyvä Theme CSS Classes, and enter your theme's classes. In WebForms 3 the same group was called Hyvä Theme Developer, with the same 16 settings. With a Hyvä default theme these values match its own forms:
Group Setting Styles Value Form Layout Form CSS Class The row that holds the form's sections Keep the default Form Layout Fieldset CSS Class One section and the gaps between its fields Keep the default Field Layout Field Block CSS Class The wrapper of one field Keep the default Input Elements Text Input CSS Class Single-line inputs form-input w-fullInput Elements Textarea CSS Class Textarea fields form-textarea w-fullInput Elements Select CSS Class Dropdowns form-select w-fullInput Elements Radio Button CSS Class Radio buttons radioInput Elements Checkbox CSS Class Checkboxes checkboxInput Elements Time Input CSS Class The hour and minute lists of a time form-select w-autoLabels and Messages Fieldset Label CSS Class A section heading Keep the default Labels and Messages Field Label CSS Class A field's label block mb-2 text-fg-secondary: the labels of the theme's Create an Account form, regular weight and grey. Orfield-label, the theme's field label: medium weight, dark and closer to the field, near the WebForms 3 lookLabels and Messages Radio Label CSS Class The caption of a radio option Keep the default Labels and Messages Checkbox Label CSS Class The caption of a checkbox option Keep the default Labels and Messages Field Comment CSS Class The hint under a field Keep the default Labels and Messages Validation Message CSS Class A field's error message messages mt-2 text-sm text-red-600Labels and Messages Success Text CSS Class The message after a submission message success"Keep the default" rows weren't compared with a theme. Their defaults set layout and spacing more than look.
-
Click Save Config.
A value replaces the WebForms classes of that element entirely, color and size included, so put the color in it
too. With messages alone, validation messages are dark, which is why the table adds the red. message success
gives the success text the theme's green message box.
Use your theme's colors
On Hyvä, point the WebForms color tokens at your theme's variables in the theme's CSS, and leave Accent Color and the other colors empty under Appearance → Modern Field Style. A color set there is printed on the form and wins.
[data-wf-part~="form"] {
--wf-input-accent: var(--color-primary);
--wf-form-step-accent: var(--color-primary);
}
The focus ring and the checked box take the theme's primary color, with the Modern style on or off.
On Luma and Breeze, MageMe_WebForms/web/css/form-theme.less in your theme can't read the theme's LESS variables:
Magento refuses an import from outside the module's folder. Write the values themselves:
[data-wf-part~="form"] {
--wf-input-accent: #1979c3;
--wf-form-step-accent: #1979c3;
}
See Theme and template overrides for where the file goes and how to make Magento build it again.
Restyle the popup window
The popup of a form is the browser's own <dialog> element. WebForms and its add-ons share one dialog script on
Luma, Hyvä and Breeze, and the browser handles the keyboard, focus and backdrop.
On Hyvä, its look comes from Tailwind classes in window.mmDialogClasses, an object with one key per part of the
window.
-
Copy the object from the WebForms Hyvä package,
view/frontend/web/js/dialog-classes.js. It has 17 keys:dialog,alert,content,alertContent,bodyOpen,swal,icon,iconSvg,icon_error,icon_success,icon_warning,icon_info,icon_question,title,html,actionsandconfirm. The dialog also reads an 18th key,box, for the wrapper of the window's content. The file has no default for it. -
Change the keys you need and print the whole object from your theme on every page:
<script>window.mmDialogClasses = {dialog: 'w-[min(600px,calc(100vw-32px))] p-0 rounded-none border-2 border-primary shadow-xl backdrop:bg-black/40',content: 'max-h-[calc(100vh-96px)] overflow-y-auto p-6',// … the other 15 keys, copied from dialog-classes.js};</script> -
Use classes your theme's Tailwind build contains. A class outside the build lands in the markup but changes nothing.
The dialog reads the object each time a window opens, so the object works whether it's declared before the page
scripts or assigned later. Each key replaces that part's default classes, with no merge: a key you leave out loses
its default classes too. Without content, for example, the window loses its padding and its scroll.
On Luma and Breeze, the window takes its look from the dialog stylesheet, which the page loads after your
theme's styles. A rule on .mm-dialog alone loses to it. Give your rule more weight, for example:
body .mm-dialog {
border-radius: 0;
border: 2px solid #1979c3;
}
What you should see
- On Luma and Breeze, fields and the Submit button match the theme's own account forms in color, border, corners, height and font. On Luma, the popup's button matches the theme's Create an Account button.
- On Hyvä, with the classes above, input boxes, dropdowns and the time field match the theme's
form-selectandform-input, the success text is the theme's green message, and Submit is the theme'sbtn btn-primary. - The form element no longer carries the class
mm-fields-modern. If it does, the Modern style is still on for that form. - The popup window carries your border and corners.
Limits
- These parts keep the WebForms look in both styles: the slide-out panel with its tab and close button, the step strip of a multi-step form, the success message on Luma and Breeze (plain text, not the theme's message box), and on Breeze the validation messages, which are WebForms' own where the theme shows the browser's hint. The File field is the browser's own control.
- The form's own stylesheet stays. On Luma and Breeze about 77 KB of form CSS is still printed next to the form. Its few colors, such as the callout, tinted sections, the character counter and the error colors, are fixed values, not your theme's variables.
- On Hyvä,
mmDialogClassesdoesn't change everything. The width of a form's popup and the padding of its content are set with important utilities by the package'sbutton/dialog-class.phtml, and the white round close button and the header spacing come frompopup.phtml. Change those with a template override. - My Account pages use the WebForms button classes in both styles (read in the code).
Troubleshooting
| Symptom | Check |
|---|---|
| You set Enable Modern Field Style to No and nothing changed | Check the scope: a store view with its own value ignores Default Config. |
| The Submit button keeps a color or size of its own | The form sets a color, variant or size on its Submit element. Reset them in the builder and publish. |
| Labels or fields are hard to read inside the form's box | A dark Form Box background sits behind the theme's fields and labels, which WebForms doesn't recolor in the theme style. Pick a lighter Background Color, or set the theme's text color for the form in the theme's CSS. |
| On Hyvä the button changed but the input boxes didn't | Fill Hyvä Theme CSS Classes, step 2 of Hyvä. |
| The popup lost its padding or its scroll | Your mmDialogClasses leaves out a key, such as content. Copy all 17 keys. |
| Your popup classes have no effect | On Hyvä, the classes aren't in the theme's Tailwind build. On Luma and Breeze, your rule has the weight of one class; see Restyle the popup window. |
| Custom Popup CSS Classes in the widget doesn't change the window | That class goes on the block inside the window, not on the window. Style the window as in Restyle the popup window. |
What's next
- Two form styles: the store owner's view of the same switch.
- Styling contract: the attributes and
--wf-*tokens to write CSS against. - Theme and template overrides: replace a template when settings aren't enough.
- Settings: Developer: every Hyvä Theme CSS Classes setting.