Skip to main content
Solved

CSS code for mandatory fields set by the layout


Forum|alt.badge.img+14

We’ve put the mandatory fields lightblue in de css custom style sheet.
However, this css code does not effect the mandatory setting from the layout.
So if we set a field mandatory in the layout it’s not highlighted in light blue.

There is this really small light red arrow in the label, but users oversee this small red star.

Is there a css change which effects the mandatory fields set by the layout as well.
We want to have ALL mandatory fields light blue en not just a part of it.
 

Best answer by Sebastiaan Meijerink

Hi,

You’re right. In the current version, the mandatory CSS class is only added for fields that are mandatory in the model, not for fields made mandatory by the layout procedure. What both cases do have in common is the field label: it always gets the class Mui-required (that’s the class that shows the red asterisk).

So if you select on the label, you catch every mandatory field, whatever made it mandatory. Replace your current rule with something like this:

/* All mandatory fields: set in the model or by the layout procedure */[data-form="control"]:has(.Mui-required) .MuiInputBase-root {  background-color: lightblue;}

If your current rule styles a different inner element, keep that part and only replace .mandatory with [data-form="control"]:has(.Mui-required).

This uses the CSS :has() selector, which all current browsers (Chrome, Edge, Firefox, Safari) support. The highlight only shows while the record is in edit mode, the same as the asterisk.

 

Sebastiaan

View original

4 replies

Forum|alt.badge.img+2

Hi,

You’re right. In the current version, the mandatory CSS class is only added for fields that are mandatory in the model, not for fields made mandatory by the layout procedure. What both cases do have in common is the field label: it always gets the class Mui-required (that’s the class that shows the red asterisk).

So if you select on the label, you catch every mandatory field, whatever made it mandatory. Replace your current rule with something like this:

/* All mandatory fields: set in the model or by the layout procedure */[data-form="control"]:has(.Mui-required) .MuiInputBase-root {  background-color: lightblue;}

If your current rule styles a different inner element, keep that part and only replace .mandatory with [data-form="control"]:has(.Mui-required).

This uses the CSS :has() selector, which all current browsers (Chrome, Edge, Firefox, Safari) support. The highlight only shows while the record is in edit mode, the same as the asterisk.

 

Sebastiaan


Forum|alt.badge.img+14
  • Author
  • Sidekick
  • October 23, 2026

Hi Sebastiaan, thanks a lot. This works! Much better now.


Forum|alt.badge.img+14
  • Author
  • Sidekick
  • October 23, 2026

However….. Now the fields are also set light blue in non-edit mode. So there now marked mandatory all the time, can we fix this as well??
Is it perhaps the location in the css where I have to put it?


Forum|alt.badge.img+14
  • Author
  • Sidekick
  • October 23, 2026

Codex helped me out!
So for everyone who wants to give the mandatory fields an accent color:
Add this piece of code to your css.

/* Verplichte velden: alleen opmaken in bewerkmodus */

/* Rand */
.light .MuiFormControl-root:has(.Mui-required):not(.non-edit-mode)
.tsf-control-outline {
    border-color: Darkblue;
}

.dark .MuiFormControl-root:has(.Mui-required):not(.non-edit-mode)
.tsf-control-outline {
    border-color: Blue;
}

/* Achtergrond */
.light .MuiFormControl-root:has(.Mui-required):not(.non-edit-mode) {
    background-color: AliceBlue;
}

.dark .MuiFormControl-root:has(.Mui-required):not(.non-edit-mode) {
    background-color: #597EA8;
}