如何不要求输入 [英] How to not require a required input
问题描述
我有一个建筑物
与一个 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
值,但到目前为止没有任何效果。
谢谢。
我很惊讶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 a
User` 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屋!