-
Notifications
You must be signed in to change notification settings - Fork 96
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
FIX SearchableDropdownField pass incorrect value on onChange event #1736
FIX SearchableDropdownField pass incorrect value on onChange event #1736
Conversation
5747604
to
50bc410
Compare
if (typeof val !== 'object') { | ||
options.forEach(option => { | ||
// eslint-disable-next-line eqeqeq | ||
if (option.value == value) { | ||
val = option; | ||
} | ||
}); | ||
} | ||
|
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.
react-select
expect to get value as an array of objects of ValueType
in the following format { label: 'label', value: 'value' }
. See discussion here.
FormBuilder.buildComponent()
set onChange props as function with 2 arguments (event and payload), but handle payload value first and redux-form set this payload value in the state. See
After we render SearchableDropdownField again we get integer value from state instead of object. So, if we pass only value that is returned back from react-select (See) then we process it and store it as an Object.toString() and get [object.Object] in view. If we pass two params then we get integer or any other value, but not object, after processing.
50bc410
to
2daaf21
Compare
2daaf21
to
038173c
Compare
I left comment in the issue: #1733 (comment) |
This PR seems to work without any problems for me. In #1733 (comment) you mentioned "this requires more careful study than simply fixing a tag display problem" - but I don't understand what problems are left? |
That's right, this PR solves the current problem and, as far as I was able to test, it does not cause regression problems. I will try to slightly reformulate my doubts about the correct operation of
Everything works fine if we process the data before sending it to the server, as for example in the case of an asset-admin and users who are allowed to view. But not in the case of searching, since the data is not processed in any way before sending and we simply transfer the object. The problem occurs in Also, after the server returns the response, we will store the value So I believe the problem is a little deeper than just This PR simply stores in state only the value for a single value field and the entire array for a multiple choice field. That is, I think if someone decides to use |
Sorry, that went a bit too deep into the weeds (too much specific technical detail) for me to be able to easily understand what problems remain.
The above suggests there's still some problem related to
Are there any specific problems related to this that you're aware of?
That's a good point. I've just tested that using the following code: <?php
namespace App\Extension;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\SearchableMultiDropdownField;
use SilverStripe\Security\Member;
class GroupSearchableFieldsExtension extends Extension
{
public function updateSearchableFields(array &$fields)
{
$fields['Members'] = [
'title' => 'Users',
'field' => SearchableMultiDropdownField::create('Members', 'Users', Member::get()),
];
}
} SilverStripe\Security\Group:
extensions:
- App\Extension\GroupSearchableFieldsExtension Searching with that field does indeed give a bad result - specifically if I select two records I get |
client/src/components/SearchableDropdownField/SearchableDropdownField.js
Show resolved
Hide resolved
Are there any specific problems outstanding beyond that? As in specific problems that cause errors or bad UX, which can be easily reproduced? |
@GuySartorelli , how I said before, the current PR fixes initial issue. For another problems that were discussed in comments I've opened new ticket #1746
No, I couldn't find any problems. I would be good to test this field created by FormBuilder. |
I've updated that issue to reflect what we discussed in slack - the main problem is that |
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.
LGTM, works well locally for single values and there's a separate issue to deal with multi values since that's a more involved problem.
Parent issue