TastyIgniter icon indicating copy to clipboard operation
TastyIgniter copied to clipboard

Selectlist values are not blankable

Open ryanmitchell opened this issue 3 years ago • 16 comments

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.

ryanmitchell avatar Jan 12 '21 08:01 ryanmitchell

Something similar to what have been done with KD? https://github.com/ryanmitchell/ti-ext-kitchendisplay/blob/4a8f1e49fc75fb1222d2e34ba0c6cedcbe0608fd/models/Views.php#L38

BreakSecurity avatar Jan 13 '21 15:01 BreakSecurity

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

ryanmitchell avatar Jan 13 '21 15:01 ryanmitchell

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

sampoyigi avatar Jan 14 '21 17:01 sampoyigi

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.

ryanmitchell avatar Jan 14 '21 18:01 ryanmitchell

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?

sampoyigi avatar Jan 19 '21 13:01 sampoyigi

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.

ryanmitchell avatar Jan 19 '21 13:01 ryanmitchell

Ok, share your field configuration

sampoyigi avatar Jan 19 '21 14:01 sampoyigi

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(),
            ],

ryanmitchell avatar Jan 19 '21 14:01 ryanmitchell

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?

sampoyigi avatar Jan 20 '21 13:01 sampoyigi

The only thing I had thought of was adding something around here: https://github.com/tastyigniter/TastyIgniter/blob/1b8315880937c9ba0e58fddd0f38321d438de64b/app/admin/widgets/Form.php#L753

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

ryanmitchell avatar Jan 20 '21 13:01 ryanmitchell

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.

sampoyigi avatar Jan 23 '21 12:01 sampoyigi

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.

ryanmitchell avatar Jan 23 '21 21:01 ryanmitchell

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

sampoyigi avatar Jan 24 '21 02:01 sampoyigi

Hmm that seems like a big change this late in the cycle? I think I can make it work by adding a “Select none” option similar to select all - give me a couple of days.

On 24 Jan 2021, at 02:26, Sam Poyigi [email protected] wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tastyigniter/TastyIgniter/issues/659#issuecomment-766278810, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMVO2TIXX6MZDWWX4DU4LS3OAOLANCNFSM4V6Z73EQ.

ryanmitchell avatar Jan 24 '21 09:01 ryanmitchell

Both issues should be fixed with the PR here: https://github.com/tastyigniter/TastyIgniter/pull/677

ryanmitchell avatar Jan 24 '21 14:01 ryanmitchell

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.

sampoyigi avatar Mar 02 '22 00:03 sampoyigi