Yii Framework Forum: ActiveField error message position - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ActiveField error message position How auto generated error message position can be changed

#1 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 13 September 2017 - 07:06 AM

I want to create an input group for first name, middle name, and last name fields, using following code:-

<div class="input-group">
<?php
echo $form->field($model, 'f_name')->textInput(['maxlength' => true, 'placeholder' => 'First Name', 'style'=>"float: left; width: 34%;"]);
echo $form->field($model, 'm_name')->textInput(['maxlength' => true, 'placeholder' => 'Middle Name', 'style'=>"float: left; width: 34%;"]);
echo $form->field($model, 'l_name')->textInput(['maxlength' => true, 'placeholder' => 'Last Name', 'style'=>"float: left; width: 34%;"]);

?>
</div>

The problem is ActiveField auto generates input, error tags. Only First name is required, and i want client validation error message to be displayed only after the three input fields on new line

how can i do this?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,361
  • Joined: 16-February 11
  • Location:Japan

Posted 13 September 2017 - 08:41 AM

I think you can consider using Html::activeTextInput() and Html::error() instead.

BaseHtml::activeTextInput(http://www.yiiframew...ctiveTextInput()-detail)
BaseHtml::error() (http://www.yiiframew...tml.html#error()-detail)
0

#3 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 14 September 2017 - 06:17 AM

View Postsoftark, on 13 September 2017 - 08:41 AM, said:

I think you can consider using Html::activeTextInput() and Html::error() instead.

BaseHtml::activeTextInput(http://www.yiiframew...ctiveTextInput()-detail)
BaseHtml::error() (http://www.yiiframew...tml.html#error()-detail)



Still not showing any error, my code is as following

<div class="input-group">
<?php
//echo $form->field($model, 'f_name')->textInput(['maxlength' => true, 'placeholder' => 'First Name']);
echo Html::activeInput('text', $model, 'f_name', ['style'=>"float: left; width: 34%;", 'class'=>'form-control', 'placeholder'=>'First']);
echo Html::activeInput('text', $model, 'm_name', ['style'=>"float: left; width: 33%;", 'class'=>'form-control', 'placeholder'=>'Middle']);
echo Html::activeInput('text', $model, 'l_name', ['style'=>"float: left; width: 33%;", 'class'=>'form-control', 'placeholder'=>'Last']);
echo Html::error($model, 'f_name');
?>
</div>
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,361
  • Joined: 16-February 11
  • Location:Japan

Posted 14 September 2017 - 09:24 AM

Well, unfortunately, I think I've found the following by testing it by myself:

Html::error() doesn't support either client-side validation or ajax validation.

So, would you please confirm it by turning off them in your form?
0

#5 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 16 September 2017 - 04:26 AM

View Postsoftark, on 14 September 2017 - 09:24 AM, said:

Well, unfortunately, I think I've found the following by testing it by myself:

Html::error() doesn't support either client-side validation or ajax validation.

So, would you please confirm it by turning off them in your form?


Yes, thats true. I have turned off both validations.
0

#6 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 18 September 2017 - 05:45 AM

View PostShahzad, on 16 September 2017 - 04:26 AM, said:

Yes, thats true. I have turned off both validations.


What else can be done, any thoughts please. How to attach client validation to a field other than ActiveForm/Field
0

#7 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,361
  • Joined: 16-February 11
  • Location:Japan

Posted 19 September 2017 - 06:34 AM

Well, I would create a form like the following using ActiveFields:
+--------------------+--------------------+------------------+
|First Name (label)  |Second Name (label) |Last name (label) |
|First Name (input)  |Second Name (input) |Last name (input) |
|First Name (error)  |Second Name (error) |Last name (error) |
+--------------------+--------------------+------------------+

It could be done by specifying ActiveField::$template (http://www.yiiframew...template-detail) and some appropriate CSS.

The labels may be totally omitted and the errors for the 2nd and 3rd names may be also omitted.
0

#8 User is offline   Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 16-March 12
  • Location:Islamabad, Pakistan

Posted 21 September 2017 - 04:42 AM

View Postsoftark, on 19 September 2017 - 06:34 AM, said:

Well, I would create a form like the following using ActiveFields:
+--------------------+--------------------+------------------+
|First Name (label)  |Second Name (label) |Last name (label) |
|First Name (input)  |Second Name (input) |Last name (input) |
|First Name (error)  |Second Name (error) |Last name (error) |
+--------------------+--------------------+------------------+

It could be done by specifying ActiveField::$template (http://www.yiiframew...template-detail) and some appropriate CSS.

The labels may be totally omitted and the errors for the 2nd and 3rd names may be also omitted.


Ok, got the idea, now the problem is
The code

echo $form->field($model, 'f_name', ['template'=>"{input}"])->textInput(['maxlength' => true]);

generates following html

<div class="form-group field-patient-f_name required">
<input type="text" id="patient-f_name" class="form-control" name="Patient[f_name]" maxlength="50">
</div>

It auto inserts the <div> tag, due to this i cannot format 3 name fields into input-group

is there anyway, that $form->field not generate these tags, i want only input tag to be generated.

thanx.
0

#9 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,361
  • Joined: 16-February 11
  • Location:Japan

Posted 22 September 2017 - 12:38 AM

Assuming you are using bootstrap, something like the following will be a hint, I hope.
It doesn't remove the enclosing 'div' tag from the field, but the 3 fields will be aligned horizontally in the form.
<div class="row">
    <div class="col-lg-6">
        <?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
        <div class="row">
            <div class="col-sm-4">
                <?= $form->field($model, 'name_1')->textInput() ?>
            </div>
            <div class="col-sm-4">
                <?= $form->field($model, 'name_2')->textInput() ?>
            </div>
            <div class="col-sm-4">
                <?= $form->field($model, 'name_3')->textInput() ?>
            </div>
        </div>
        <?= $form->field($model, 'email') ?>
        <?= $form->field($model, 'subject') ?>
        <?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
        <div class="form-group">
            <?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
        </div>
        <?php ActiveForm::end(); ?>
    </div>
</div>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users