Can any one know how to put asterisk in front of each required fields.
I have lots of fields in the form I want put a red asterisk in front of required field.
I went through these references but unable to understand
need help how use these reference in which file do I need to update the css.
Pasman
(Pasman P)
May 24, 2015, 7:28pm
2
this asterisk is on my forms out of box.
what is your yii version and theme ?
1 Like
amit5992
(Gupta5992amit)
May 25, 2015, 5:58am
3
Add this Css…
for form required field…
form div.required label.control-label:after {
content:" * ";
color:red;
}
4 Likes
AnilBafila
(Anilbafiladev)
May 29, 2015, 10:57am
4
in which file do I need to put this code
amit5992
(Gupta5992amit)
May 29, 2015, 11:00am
5
should you use default yii css file
site.css
?
so, put about code in
site.css
or which css file you might included
AnilBafila
(Anilbafiladev)
June 1, 2015, 12:44pm
6
Thanks Amit5992 its working
Thank you Amit5992. Very Nice solution!!
I’m using Yii2 Latest release 2.0.45 with bootstrap 4, so i have to change control-label to col-form-label in order to working.
form div.required label.col-form-label:after {
content: " * ";
color: red;
}
snathan
(snathan)
July 5, 2022, 2:54pm
10
This can be handled at the layout - as opposed to each form.
Yii by default adds the “required” class to the fields that are required. See below:
<div class="form-group field-calcmortgage-loantype required">
With that already taken care of, what is left is defining the required class in the layout - see style section. I have added a special HTML character but you can simple add an asterisk if that’s all you desire. And once you do that, you never ever have to worry about marking required fields anymore (as long as you make sure the layout is customized).
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
<style>
...
...
.required:before { content:" \269D"; color:red;}
</style>
</head>