bluzky / nice-select2

A lightweight vanilla javascript library that replaces native select elements with customizable dropdowns
https://bluzky.github.io/nice-select2/
MIT License
361 stars 60 forks source link

Purpose of data-display? #48

Closed mrdarrengriffin closed 1 year ago

mrdarrengriffin commented 1 year ago

Looking at the example on https://bluzky.github.io/nice-select2/, the data-display functionality does not work.

From my understanding, it allows the user to provide alternative text to use when the option is selected. If this is the case, the example should show "Select" when the "Nothing" option is chosen. Not sure if I am misunderstanding this feature, but some clarification would be helpful

Thanks

Tsjippy commented 1 year ago

I see thats broken, fixed now

LuigiPulcini commented 5 months ago

The fix to this issue (1 March 2023) was never released since the latest release 2.1.0 is from 23 January 2023. As a result, the latest package available for npm is 2.1.0 and doesn't contain this fix.

Tsjippy commented 5 months ago

Sorry for the delay, I published it

1ucay commented 2 months ago

with woocommerce we can now use flags in country selector, if we have phone picker js/css on page => https://github.com/jackocnr/intl-tel-input

add_filter( 'woocommerce_form_field', 'country_woocommerce_form_field', 10, 4 );
function country_woocommerce_form_field( $field, $key, $args, $value ) {

    switch ( $args['type'] ) {
        case 'country':

            $field = preg_replace('/(<select name="(.*?)country"(.*?)>)(.*?)<\/select>/', '$1', $field );

            $countries = 'shipping_country' === $key ? WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries();

            foreach ( $countries as $ckey => $cvalue ) {
                $field .= '<option data-display="<div class=\'iti__flag-box\'><div class=\'iti__flag iti__' . mb_strtolower( esc_attr( $ckey ) ) .'\'></div></div>' . esc_html( $cvalue ) . '" value="' . esc_attr( $ckey ) . '" ' . selected( $value, $ckey, false ) . '>' . esc_html( $cvalue ) . '</option>';
            }

            $field .= '</select>';

            break;
    }

    return $field;
}