Jump to content

AsmSelect: add text to first option (Please select...)


Recommended Posts

Posted

I found no way to add text "Please select..." as the first item to an AsmSelect field. Using PHP I could add a disabled option but an empty first item is always prepended to the options list.

I also checked the JavaScript options but found no way to do this.

Is there something I overlooked? I can add this feature with a few lines of extra JS but it would be better if there were an "official" way.

Posted

Most of its magic happens in JS. See how I do it Menu Builder if at all helpful. I hooked into its render method  and injected my custom JS file (jquery.asmselect-mb.js) which overrides its native jquery.asmselect.js. See this thread for the results (toward the end)

  • Like 1
Posted

Thanks, I will look into them. As for now, I think it's easier to manipulate the select field on document.ready() - of course there might be issues that I can't foresee.

Posted

I solved it this way - a bit hacky but as it's only a cosmetic issue, it will do.

  • In the module I needed this feature I added a "data-asm-placeholder" to the asmSelect field
  • in module JS I added a $(function () { ... } inside document.ready() where I set the asmSelect field's first option text to the value set in data-asm-placeholder

post-3156-0-96826300-1445460453_thumb.pn

$(document).ready(function () {

    // other code here

    $(function () {
        $('select[data-asm-placeholder!=""][data-asm-placeholder]').each(function () {

            var placeholder = $(this).data('asmPlaceholder');

            if (placeholder) {
                $(this).parent().find('.asmSelect').find('option:first').attr('selected', true).attr('disabled', true).text(placeholder);
            }
        });
    });
});
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...