admin管理员组文章数量:1327972
I have form generated with HTML helper:
<div class="row">
<div class='form-group col-lg-6 col-sm-6'>
<?= HTML::label('Name:','PropertyContactsNew',['class' => 'control-label']); ?>
<?= HTML::textInput("PropertyContactsNew[{$slug_other_contacts}][name][]", '', ['maxlength' => 50, 'class'=>'form-control']) ?>
</div>
<div class='form-group col-lg-6 col-sm-6'>
<?= HTML::label('Company:','PropertyContactsNew',['class' => 'control-label']); ?>
<?= HTML::textInput("PropertyContactsNew[{$slug_other_contacts}][pany][]", '', ['maxlength' => 100, 'class'=>'form-control']) ?>
</div>
</div>
Is there a way mark form fields required and prevent form from submitting in case the it is empty, just like the ActiveForm does (I can not use ActiveForm for some reasons) or should I use js library to do this?
I have form generated with HTML helper:
<div class="row">
<div class='form-group col-lg-6 col-sm-6'>
<?= HTML::label('Name:','PropertyContactsNew',['class' => 'control-label']); ?>
<?= HTML::textInput("PropertyContactsNew[{$slug_other_contacts}][name][]", '', ['maxlength' => 50, 'class'=>'form-control']) ?>
</div>
<div class='form-group col-lg-6 col-sm-6'>
<?= HTML::label('Company:','PropertyContactsNew',['class' => 'control-label']); ?>
<?= HTML::textInput("PropertyContactsNew[{$slug_other_contacts}][pany][]", '', ['maxlength' => 100, 'class'=>'form-control']) ?>
</div>
</div>
Is there a way mark form fields required and prevent form from submitting in case the it is empty, just like the ActiveForm does (I can not use ActiveForm for some reasons) or should I use js library to do this?
Share Improve this question asked Nov 27, 2015 at 15:45 Avag SargsyanAvag Sargsyan 2,5234 gold badges32 silver badges45 bronze badges3 Answers
Reset to default 3Someone might need
<?= HTML::label('Name:','PropertyContactsNew',['class' => 'control-label','required'=>true]); ?>
I think that you could create a FormModel that extends Model class, so you can handle every validation you need.
Red required
Only this code is working for me. Div with class required
<div class="form-group required">
<?= Html::label('Pressed digit', 'pressed_digit', ['class' => 'control-label']) ?>
</div>
本文标签: javascriptYii2 HTML helper input make requiredStack Overflow
版权声明:本文标题:javascript - Yii2 HTML helper input make required - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742251076a2440769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论