-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] read_only and disabled attributes (closes #1974) #3193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1299,6 +1299,36 @@ public function testHidden() | |||
); | |||
} | |||
|
|||
public function testReadOnly() | |||
{ | |||
$form = $this->factory->createNamed('text', 'na&me', null, array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a name
instead of na&me
. It will make things easier as the current refactoring will forbid &
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. If you care to enlighten me, why is the ampersand included in the examples in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test for correct escaping.
I changed Perhaps something else, like @bschussek, others, any thoughts? |
@@ -697,10 +688,9 @@ public function isValid() | |||
return false; | |||
} | |||
|
|||
if (!$this->readOnly) { | |||
if (!$this->disabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use !$this->isDisabled()
here (returns true if any parent is disabled), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Did the same for bind
function as well.
Please prefix commits with the affected component, if applicable. |
@bschussek Prefixed. Please also see see to this question |
Commits ------- de253dd [Form] read_only and disabled attributes Discussion ---------- [Form] read_only and disabled attributes (closes #1974) 1. Removed ``readOnly`` property from ``Form``, as it is no longer required 2. Introduced ``disabled`` property to ``Form``, behaves exactly like ``readOnly`` used to 3. Added ``disabled`` property to fields, defaults to ``false``, renders as ``disabled="disabled"`` 4. A field with positive ``read_only`` property now renders as ``readonly="readonly"`` --------------------------------------------------------------------------- by helmer at 2012-01-26T17:46:17Z I changed ``Form`` and ``FormBuilder`` property ``readOnly`` to ``disabled``. On second thought, this is perhaps not such good change - while readOnly somewhat implied the use-case, disabled no longer does. Perhaps something else, like ``bindable`` (as not to confuse with read_only attribute of Fields)? @bschussek, others, any thoughts? --------------------------------------------------------------------------- by bschussek at 2012-01-31T06:53:59Z Please prefix commits with the affected component, if applicable. --------------------------------------------------------------------------- by helmer at 2012-01-31T08:41:03Z @bschussek Prefixed. Please also see see to [this question](#3193 (comment))
This PR is still flawed in that the read_only option does not regard the read_only setting of parent fields. @helmer: Can you fix this? |
@bschussek Please explain with an usecase, I did not quite get it .. complex (ie collection) fields get rendered incorrectly? |
@helmer: exactly |
@bschussek Hmm, my test-case passes (as you can see both attributes are there) .. please elaborate: Controller
View
Output
|
@helmer: Remove "disabled" and leave only "read_only". As you see, "readonly" is missing from the radio buttons. |
@bschussek I must be getting blind, the pasted snippet clearly lacked |
@helmer This is not the correct way to solve it. Instead you should solve it generally in FieldType::buildView() by accessing the "read_only" attribute of the parent view object (because only here we already know the specific form hierarchy). |
@bschussek Sorry, but the form/field/view relation and hierarchy is a bit beyond me. After dumping around for an hour I still cannot quite grasp it. Views with no parent take their read_only value from form attribute, views with parent should take it from parent view options. Still, the following stripped down version does not work and I'm suspecting some magic: FieldType::buildView
This does not really make sense to me and I cannot invest more time in it currently. |
You're basically there :)
|
@@ -174,27 +174,27 @@ public function getData() | |||
} | |||
|
|||
/** | |||
* Set whether the form is read only | |||
* Set whether the form is disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing dot
the translation domain is already passed to the radio fields in the choice type: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L199 |
@stof True, though bschussek said it is not most correct way to do it, so it was rather a small refactor request. Why I mentioned it is because Im a bit concerned - ie the logic of "disabled" fields is taken from "Form" class (in which resides the inheritance logic as well), whereas "readonly" inheritance is handled locally and not on "Form" object. Same as "disabled" goes for "required" .. it is all just a tad messy imo and takes time to comprehend. Perhaps a critical view on how the options are handled and what classes hold the logic and how to reduce the amount of complexity is necessary? Or .. maybe its just me :) |
@helmer: Can you open a PR referencing this one so that we do not loose track of your work (as this PR is closed now)? Thanks. |
@helmer readonly is used only for the rendering. disabled is also used in the Form class to disable the binding (for a form and all its children). It is not just a rendering variable |
@fabpot Yupp, in a sec. |
the point is that all options don't have the same effect in a form. They are not all used for the same sort of things |
@stof You are missing my point here. Lets take for example |
@helmer Why is it hard to follow? If the whole is disabled, parts of it are disabled. If the whole is read only, parts of it are read only too. This way you can also easily set a whole form (or subform) to read only. |
@helmer if you take it only from the option, you will not disable the field when its parent is disabled, except if you handle the inheritance of the disabled state in 2 places. |
Commits ------- 8321593 [Form] DRYed ChoiceType 0753cee [Form] Fixed read_only attribute for expanded fields Discussion ---------- [Form] Fixed read_only attribute for expanded fields Expanded choice widgets lose the knowledge of read_only attribute value. Fixes bug introduced by #3193 --------------------------------------------------------------------------- by helmer at 2012-02-02T16:24:50Z Please hold before merging, @bschussek had some thoughts about my changes in ``ChoiceType``, waiting for feedback. --------------------------------------------------------------------------- by bschussek at 2012-02-02T16:33:12Z I'm fine with the refactoring then, but please split it into two commits at least. The changes in ChoiceType have nothing in common with the actual issue here. --------------------------------------------------------------------------- by helmer at 2012-02-02T19:40:39Z Tests added. --------------------------------------------------------------------------- by bschussek at 2012-02-03T10:14:32Z Great, thanks. @fabpot 👍
Commits ------- de253dd [Form] read_only and disabled attributes Discussion ---------- [Form] read_only and disabled attributes (closes #1974) 1. Removed ``readOnly`` property from ``Form``, as it is no longer required 2. Introduced ``disabled`` property to ``Form``, behaves exactly like ``readOnly`` used to 3. Added ``disabled`` property to fields, defaults to ``false``, renders as ``disabled="disabled"`` 4. A field with positive ``read_only`` property now renders as ``readonly="readonly"`` --------------------------------------------------------------------------- by helmer at 2012-01-26T17:46:17Z I changed ``Form`` and ``FormBuilder`` property ``readOnly`` to ``disabled``. On second thought, this is perhaps not such good change - while readOnly somewhat implied the use-case, disabled no longer does. Perhaps something else, like ``bindable`` (as not to confuse with read_only attribute of Fields)? @bschussek, others, any thoughts? --------------------------------------------------------------------------- by bschussek at 2012-01-31T06:53:59Z Please prefix commits with the affected component, if applicable. --------------------------------------------------------------------------- by helmer at 2012-01-31T08:41:03Z @bschussek Prefixed. Please also see see to [this question](symfony/symfony#3193 (comment))
readOnly
property fromForm
, as it is no longer requireddisabled
property toForm
, behaves exactly likereadOnly
used todisabled
property to fields, defaults tofalse
, renders asdisabled="disabled"
read_only
property now renders asreadonly="readonly"