I'm using yiibooster and it is really good extension for the frontend, my issues now is that I want to remove the red * that is rendered in the required fields but maintaining the required validator in the model, anyone knows how to do this????

thankss

有帮助吗?

解决方案 2

If you want to achieve what you want easily, I suggest you to do like below, which is simplest way(in my view point):

Just try to find * selector(the ID or CLASS) name.(using a firebug or any inspector) Then just do like below in your document.ready():

$(SELECTOR).remove();

NOTES

  • THE * MIGHT BE CREATED DYNAMICALLY
  • THIS IS JUST AN SUGGESTION, YOU CAN FIND ANY OTHER POSSIBLE WAYS SUCH AS CHANGING THE CSS CLASS IN ORDER TO DO DISPLAY:NONE OR SOURCE MODIFICATION

其他提示

This is an example of a label generated by a required field validator:

<label for="User_email" class="required">
    Email Address <span class="required">*</span>
</label>

Therefore, you can hide it by adding this class to your site's CSS:

span.required {
    display: none;
}
<?php echo $form->textFieldGroup($model, 'username',array('label'=>Yii::t('model','Username'))); ?>

or edit line 1223 of TbActiveForm.php from

echo $this->labelEx($model, $attribute, $options['labelOptions']);

to

echo $this->label($model, $attribute, $options['labelOptions']);

Red * is adding according to your validators definition in your model. you have two options.
First in your model add On => 'scenario name' for required validator for the property you want. so you can control the behavior of yii-booster components because they only apply those rules which matches the scenario of the model. for example:

array('password_repeat', 'required', 'on'=>'register'),

It will show Red * only in register scenario (if you set it via $model->setScenario('register');) and in normal times no red * will shown.

Another option for you is when you are creating the form element based on the property marked required by validator rules in model, you can prevent that * from showing but this way will not ignore that validation rule and if you try to submit the form while this form field is empty you will get error from yii (because you just solve showing but in background you have your required validator). for this method, you only need to provide label in your yii-booster form element:

<?php echo $form->textFieldGroup($model,'textField',
            array(
                'wrapperHtmlOptions' => array(
                    'class' => 'col-sm-5',
                ),
                'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.',
         >>>>>  'label' => 'Your new value for label which will have no red *',
            )
        ); ?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top