如何不要求输入 [英] How to not require a required input

查看:73
本文介绍了如何不要求输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个建筑物与一个 User 相关联。 User 也可以注册,登录等。我设置了我的验证,以便键 User 字段(例如,电子邮件名称等)。



何时我创建了建筑物,还提供了当场关联用户的功能。我的建筑表单具有该关键用户信息的输入:

 <?php echo $ this-> Form->输入('User.first_name')吗? 
<?php echo $ this-> Form-> input('User.last_name')?>
<?php echo $ this-> Form-> input('User.email')?>

但是,我不想将这些输入表示为必填项b / c我希望用户从而能够创建建筑物而不必创建 User`记录。我找不到方法是从验证规则放置的div中删除所需的类。



我尝试了'required'=>的各种组合false 并设置 class 值,但到目前为止没有任何效果。



谢谢。

解决方案 div>

我很惊讶deceze的解决方案对我不起作用(也许我做错了什么),但最终我不得不使用Javascript从每个字段的div中手动删除了所需的类。 / p>

I have a Building that is associated with a User. A User can also register, login, etc. I have my validation set so that key User fields (e.g. email, name, etc.) are required.

When I create a building, I'm also offering the ability to associate a user on the spot. My building form has inputs for that key user info:

<?php echo $this->Form->input( 'User.first_name' ) ?>
<?php echo $this->Form->input( 'User.last_name' ) ?>
<?php echo $this->Form->input( 'User.email' ) ?>

However, I don't want those inputs to be indicated as required b/c I want the user to be able to create a Building without necessarily creating aUser` record. What I can't find a way to do is to remove the required class from the div that is being put there by the validation rule.

I've tried various combinations of 'required' => false and setting the class value, but nothing has worked so far. Is there a good way to un-require a form input?

Thanks.

解决方案

I'm surprised that deceze's solution didn't work for me (maybe I just did something wrong), but I ended up having to use Javascript to "manually" remove the required class from each field's containing div.

这篇关于如何不要求输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆