Symfony 2 form field radio required=false?
up vote
4
down vote
favorite
This is part of my entity class :
/**
* @var integer
*
* @ORMColumn(name="student", type="integer", nullable=true)
*/
private $student;
This part of my form class :
$builder
->add('student', 'choice', ['label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
])
;
Ad this is output :
<input id="xxxxx_0" type="radio" value="4" required="required" name="xxxxx[student]">
<label class="required" for="xxxxxV_student_0">Nie</label>
...
My problem is that my input tag should not have attribute "required" becouse I have set nullable=true in entity.
forms symfony doctrine2 choice
add a comment |
up vote
4
down vote
favorite
This is part of my entity class :
/**
* @var integer
*
* @ORMColumn(name="student", type="integer", nullable=true)
*/
private $student;
This part of my form class :
$builder
->add('student', 'choice', ['label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
])
;
Ad this is output :
<input id="xxxxx_0" type="radio" value="4" required="required" name="xxxxx[student]">
<label class="required" for="xxxxxV_student_0">Nie</label>
...
My problem is that my input tag should not have attribute "required" becouse I have set nullable=true in entity.
forms symfony doctrine2 choice
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
This is part of my entity class :
/**
* @var integer
*
* @ORMColumn(name="student", type="integer", nullable=true)
*/
private $student;
This part of my form class :
$builder
->add('student', 'choice', ['label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
])
;
Ad this is output :
<input id="xxxxx_0" type="radio" value="4" required="required" name="xxxxx[student]">
<label class="required" for="xxxxxV_student_0">Nie</label>
...
My problem is that my input tag should not have attribute "required" becouse I have set nullable=true in entity.
forms symfony doctrine2 choice
This is part of my entity class :
/**
* @var integer
*
* @ORMColumn(name="student", type="integer", nullable=true)
*/
private $student;
This part of my form class :
$builder
->add('student', 'choice', ['label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
])
;
Ad this is output :
<input id="xxxxx_0" type="radio" value="4" required="required" name="xxxxx[student]">
<label class="required" for="xxxxxV_student_0">Nie</label>
...
My problem is that my input tag should not have attribute "required" becouse I have set nullable=true in entity.
forms symfony doctrine2 choice
forms symfony doctrine2 choice
asked Nov 4 '13 at 10:46
user2156980
2901314
2901314
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
17
down vote
accepted
The solution is required => false and empty_value => false
$builder
->add('student', 'choice', [
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'empty_value' => false
]);
6
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
add a comment |
up vote
4
down vote
As described here,
required
type: Boolean default: true
required option default value is set to true, so you should then set it to false.
builder->add('student', 'choice', array(
'label'=> false,
'expanded' => true,
'required' => false,
//...
))
;
Also, you can read from documentation that,
This is superficial and independent from validation. At best, if you let Symfony
guess your field type, then the value of this option will be guessed from your
validation information.
You need then to set a validation rule that take into account the fact that your field should not be required in order to let your form set the right value of required.
This may probably help.
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
|
show 1 more comment
up vote
0
down vote
Since Symfony 3.0 empty_value is removed and you need to use placeholder instead:
$builder
->add(
'student',
'choice',
[
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'placeholder' => null
]
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19766060%2fsymfony-2-form-field-radio-required-false%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
17
down vote
accepted
The solution is required => false and empty_value => false
$builder
->add('student', 'choice', [
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'empty_value' => false
]);
6
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
add a comment |
up vote
17
down vote
accepted
The solution is required => false and empty_value => false
$builder
->add('student', 'choice', [
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'empty_value' => false
]);
6
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
add a comment |
up vote
17
down vote
accepted
up vote
17
down vote
accepted
The solution is required => false and empty_value => false
$builder
->add('student', 'choice', [
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'empty_value' => false
]);
The solution is required => false and empty_value => false
$builder
->add('student', 'choice', [
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'empty_value' => false
]);
edited Nov 11 at 20:04
Thomas Landauer
2,26811646
2,26811646
answered Nov 4 '13 at 11:42
user2156980
2901314
2901314
6
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
add a comment |
6
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
6
6
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
this solution is good until Symfony 2.8, then you must use "placeholder" option, since "empty_value" has been deprecated in 2.7 (and removed in 3.0)
– Massimiliano Arione
Oct 13 '15 at 13:05
add a comment |
up vote
4
down vote
As described here,
required
type: Boolean default: true
required option default value is set to true, so you should then set it to false.
builder->add('student', 'choice', array(
'label'=> false,
'expanded' => true,
'required' => false,
//...
))
;
Also, you can read from documentation that,
This is superficial and independent from validation. At best, if you let Symfony
guess your field type, then the value of this option will be guessed from your
validation information.
You need then to set a validation rule that take into account the fact that your field should not be required in order to let your form set the right value of required.
This may probably help.
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
|
show 1 more comment
up vote
4
down vote
As described here,
required
type: Boolean default: true
required option default value is set to true, so you should then set it to false.
builder->add('student', 'choice', array(
'label'=> false,
'expanded' => true,
'required' => false,
//...
))
;
Also, you can read from documentation that,
This is superficial and independent from validation. At best, if you let Symfony
guess your field type, then the value of this option will be guessed from your
validation information.
You need then to set a validation rule that take into account the fact that your field should not be required in order to let your form set the right value of required.
This may probably help.
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
|
show 1 more comment
up vote
4
down vote
up vote
4
down vote
As described here,
required
type: Boolean default: true
required option default value is set to true, so you should then set it to false.
builder->add('student', 'choice', array(
'label'=> false,
'expanded' => true,
'required' => false,
//...
))
;
Also, you can read from documentation that,
This is superficial and independent from validation. At best, if you let Symfony
guess your field type, then the value of this option will be guessed from your
validation information.
You need then to set a validation rule that take into account the fact that your field should not be required in order to let your form set the right value of required.
This may probably help.
As described here,
required
type: Boolean default: true
required option default value is set to true, so you should then set it to false.
builder->add('student', 'choice', array(
'label'=> false,
'expanded' => true,
'required' => false,
//...
))
;
Also, you can read from documentation that,
This is superficial and independent from validation. At best, if you let Symfony
guess your field type, then the value of this option will be guessed from your
validation information.
You need then to set a validation rule that take into account the fact that your field should not be required in order to let your form set the right value of required.
This may probably help.
edited May 23 '17 at 11:54
Community♦
11
11
answered Nov 4 '13 at 10:55
Ahmed Siouani
11.7k105166
11.7k105166
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
|
show 1 more comment
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
I had tried this before and this adding extra radio on top and I don't want that.
– user2156980
Nov 4 '13 at 11:00
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
Ok, so then check the update and let me know if it helps.
– Ahmed Siouani
Nov 4 '13 at 11:04
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
I have set * @AssertChoice(choices = 4,3,2,1, null) but nothing changed.
– user2156980
Nov 4 '13 at 11:29
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
OK I have found the solution 'required' => false, 'empty_value' => false
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
Thank You for your help
– user2156980
Nov 4 '13 at 11:40
|
show 1 more comment
up vote
0
down vote
Since Symfony 3.0 empty_value is removed and you need to use placeholder instead:
$builder
->add(
'student',
'choice',
[
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'placeholder' => null
]
);
add a comment |
up vote
0
down vote
Since Symfony 3.0 empty_value is removed and you need to use placeholder instead:
$builder
->add(
'student',
'choice',
[
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'placeholder' => null
]
);
add a comment |
up vote
0
down vote
up vote
0
down vote
Since Symfony 3.0 empty_value is removed and you need to use placeholder instead:
$builder
->add(
'student',
'choice',
[
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'placeholder' => null
]
);
Since Symfony 3.0 empty_value is removed and you need to use placeholder instead:
$builder
->add(
'student',
'choice',
[
'label'=> false,
'expanded' => true,
'choices' => (Array)new StudentEnum(),
'required' => false,
'placeholder' => null
]
);
edited Nov 11 at 20:09
community wiki
2 revs, 2 users 96%
k0pernikus
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19766060%2fsymfony-2-form-field-radio-required-false%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown