-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Inconsistent use of EnumerationField #8460
Comments
Something that would help would be to change the
With this we would always be reading/writing the records consistenly. That still leaves the issue with trying to open the Edit view with |
Do you changes keep the |
I'm positive it should, but I haven't had a chance to implement them and try. |
Fixed by #8789. |
ref: #8298 (@GiuseppeMusso-Laser @HermesSbicego-Laser @sebastienros )
I think there is an issue in how we are using/editing the values in
EnumerationField
.The possible values that a user can select are configured in
EnumerationFieldSettings.Options
: this property is a string that contains all the possible options for theEnumerationField
, one per line. For example:Then, depending on the selection of
EnumerationFieldSettings.ListMode
, the editor displays differently. SeeOrchard/src/Orchard.Web/Modules/Orchard.Fields/Views/EditorTemplates/Fields/Enumeration.Edit.cshtml
Line 9 in ca86ec9
The result of this is that if
ListMode
isDropdown
orRadioButton
the driver will set theValue
property of theEnumerationField
directly. On the other hand, ifListMode
isListBox
orCheckbox
the driver will set theSelectedValues
property. Note that neither case adds a form element for the property it's not setting, which would then be bound to null.As was pointed out in the PR linked above, this results in
Value
having different values depending on which is the configuration of the Field.Supposing I want to select the value
foo
, with the first two settings I will have that the values saved in the record isfoo
, while with the other two settings the value in the record will be;foo;
.If, from the second case, we changed
ListMode
to eitherDropdown
orRadioButton
, we would not see the value offoo
selected in the form, because the propertyValue
has those semicolons. On save/update then,Value
would be unset (assuming validation allows it).In #8298 we propose to remove those surrounding semicolons; @sebastienros pointed out that having those allows the better identify the values in SQL queries.
I agree with @sebastienros that those semicolons help somewhat in
contains
SQL queries.The "real" issue I see is that the
EnumerationField
currently has two incompatible ways it's being used. One (for example whenListMode
isDropdown
orRadioButton
) whereValue
is set and used directly; the other (for example whenListMode
isListBox
orCheckbox
) where we go throughSelectedValues
.While the latter works with data as saved by the former, the reverse is not true.
Changing the setter method as was proposed in the PR would mitigate the issues we see when we have set
SelectedValues
and are trying to show an editor whereListMode
isDropdown
orRadioButton
, as long as we had only set a single value.On the other hand, changing that setter method for
SelectedValues
would "break" existing queries that depend on the current formatting of the string.Another possible mitigation would be having this code in the GET Editor method of the
EnumerationFieldDriver
:(that basically reads as "if we should only have selected at most a value, and we have at least one, that is the value") as well as:
in the POST Editor method to ensure saving is also correct.
Note that the latter is not strictly required for the drivers, but it ensures that the
Value
in the records is saved consistently. However this latter snippet breaks a scenario where you had been using anEnumerationField
withListMode
asDropdown
orRadioButton
(so theValue
was saved without semicolons) and had a query with an Equals rather than a Contains (because theEnumerationField
was set to have a single value anyway).The text was updated successfully, but these errors were encountered: