Yii2: Implement "Required Asterisk Icon" next to Label of required fields.

Created on 19 Jan 2014  路  13Comments  路  Source: yiisoft/yii2

<i class="fa fa-asterisk text-danger"></i>

Or

<span class="required">*</span>
.required{
      color:red;
}
question enhancement

Most helpful comment

There is better solution to remove the red start after each radiolist item - just filter it in selector by control-label class

div.required label.control-label:after {
    content: " *";
    color: red;
}

All 13 comments

@dilip-vishwa Please read about html5 and css3 and way how required fields can be created using modern technologies.

@creocoder what do you mean exactly?

@samdark maybe

Adds ActiveForm::$requiredCssClass to label tag too, i.e.

<label class="required">Label</label>
label.required:after {content: " *"; color: red;}

@slavcodev Yes, thats what i mean exactly

The benefit, we don't need extra method labelEx() :D

Looks like a good solution. Much better than extra method.

This should be all you need:

div.required label:after {
    content: " *";
    color: red;
}

No need to change anything in form.

div.required label:after {
    content: " *";
    color: red;
}

Using radioList i get * for all the options of the list. How can i avoid that ?

you can try adding different css class to different label types and apply different style based on that.

This was my solution to remove the red start after each radiolist items.

div.required label.radio-inline:after {
    content: " ";
    color: inherit;
}

There is better solution to remove the red start after each radiolist item - just filter it in selector by control-label class

div.required label.control-label:after {
    content: " *";
    color: red;
}

Hi cebe,
div.required label:after {
content: " *";
color: red;
}
is a good solution but it is not working in hosted server

Thank you for your question.
In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

_This is an automated comment, triggered by adding the label question._

Was this page helpful?
0 / 5 - 0 ratings