shzi
(Shahzadwise)
September 13, 2017, 12:06pm
1
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?
softark
(Softark)
September 13, 2017, 1:41pm
2
shzi
(Shahzadwise)
September 14, 2017, 11:17am
3
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>
softark
(Softark)
September 14, 2017, 2:24pm
4
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?
shzi
(Shahzadwise)
September 16, 2017, 9:26am
5
softark:
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.
shzi
(Shahzadwise)
September 18, 2017, 10:45am
6
What else can be done, any thoughts please. How to attach client validation to a field other than ActiveForm/Field
softark
(Softark)
September 19, 2017, 11:34am
7
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.yiiframework.com/doc-2.0/yii-widgets-activefield.html#$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.
shzi
(Shahzadwise)
September 21, 2017, 9:42am
8
softark:
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.yiiframework.com/doc-2.0/yii-widgets-activefield.html#$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.
softark
(Softark)
September 22, 2017, 5:38am
9
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>