Skip to content
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

Selectlist values are not blankable #659

Open
ryanmitchell opened this issue Jan 12, 2021 · 16 comments
Open

Selectlist values are not blankable #659

ryanmitchell opened this issue Jan 12, 2021 · 16 comments

Comments

@ryanmitchell
Copy link
Member

Raising as an issue instead of a PR as Im not sure how best to handle it.

The issue is that select lists cant be blanked once they have a value, even if they are not required. So to replicate, add a value, then save, then remove the value, and what you saved persists.

@BreakSecurity
Copy link
Contributor

@ryanmitchell
Copy link
Member Author

Yep that’s my work around. Needs to be handled better in core.

@sampoyigi
Copy link
Member

Using the placeholder field property you can add an empty option.. See the language form field in staff_model.php

@ryanmitchell
Copy link
Member Author

Yeah I tried that, it doesnt seem to work with select list - because there is no form field value present it treats the field as missing so doesnt update the value.

@sampoyigi
Copy link
Member

Using the language field on the admin staff form as an example.. I'm able to create a staff with multiple languages and then update the same staff with no language selected, so somehow the form field is passing the right value? or am I missing something?

@ryanmitchell
Copy link
Member Author

ryanmitchell commented Jan 19, 2021

Maybe the difference is that the staff model field is a relation not a select list? I've tried quite a few ways of handling it (and have a work around), but a straight up standard select list cant be blanked.

@sampoyigi
Copy link
Member

Ok, share your field configuration

@ryanmitchell
Copy link
Member Author

From the loyalty extension I'm working on...

            'spending_categories' => [
                'tab' => 'lang:igniter.coupons::default.text_tab_restrictions',
                'label' => 'lang:igniter.coupons::default.label_categories',
                'type' => 'selectlist',
                'options' => \Admin\Models\Categories_model::getDropdownOptions(),
            ],

@sampoyigi
Copy link
Member

I see what you mean with the form field value, apart from the workaround in the KD extension, how would you fix this within the field_ selectlist file?

@ryanmitchell
Copy link
Member Author

The only thing I had thought of was adding something around here:

$parts = name_to_array($field->fieldName);

if type is select list and multiple then add a blank value if not present in $data - feels hacky but was the best i could come up with

@sampoyigi
Copy link
Member

Ok, I see what you mean with the values but adding the placeholder option actually works, it sends an empty string array as the field value which in turn removes the value from the db

        'options[spending_categories]' => [
            'tab' => 'lang:igniter.coupons::default.text_tab_restrictions',
            'label' => 'lang:igniter.coupons::default.label_categories',
            'type' => 'selectlist',
            'options' => \Admin\Models\Categories_model::getDropdownOptions(),
            'placeholder' => 'please select',
        ],

Another thing we can do is look into the bootstrap-multiselect js plugin to see if we can send an empty string/array when none is selected.

@ryanmitchell
Copy link
Member Author

ryanmitchell commented Jan 23, 2021

I see what you mean - you need to select the placeholder value though - if you select nothing is comes through blank? Doesnt seem intuitive to me. I'll look into the JS library and see if there is a way of always passing a value.

Another related issue is the styling - see how the label from the next field overlaps here:
Screenshot 2021-01-23 at 21 40 27
I couldn't figure out where the z-index was coming from.

@sampoyigi
Copy link
Member

Yea the bootstrap-multiselect plugin is a bit messy, maybe we can find a replacement for it?

@ryanmitchell
Copy link
Member Author

ryanmitchell commented Jan 24, 2021 via email

@ryanmitchell
Copy link
Member Author

ryanmitchell commented Jan 24, 2021

Both issues should be fixed with the PR here:
#677

@sampoyigi
Copy link
Member

This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider the Dedicated Support Service where a Service Level Agreement is offered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants