سؤال

I am working in magento 1.9 . I am making a muliselect field. I want to select all fields on single click . Did magento 1.9 gave such tag by default ? . My code in system.xml looks like .

<serviceOptions>
    <label>Domestic Services </label>
    <frontend_type>multiselect</frontend_type>
    <source_model>FedExSmall/Source_FedExSmallServices</source_model>
    <sort_order>12</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <can_be_empty>1</can_be_empty>
    <show_in_store>1</show_in_store>
</serviceOptions>

Thank you in advance !

هل كانت مفيدة؟

المحلول

You can do with xml, js

  1. Add checkbox input after your <serviceOptions> node like this:

    <checkall translate="label">
        <label>Check all services</label>
        <class>Check-all-services</class>
        <frontend_type>checkbox</frontend_type>
        <sort_order>13</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
    </checkall>
    
  2. You add this js code in your js admin

    $('#sd_general_general_checkall').click(function() {
        if($('#sd_general_general_checkall').is(":checked")) {
            $('#sd_general_general_serviceOptions option').prop('selected', true);
        } else {
            $('#sd_general_general_serviceOptions option').prop('selected', false);
        }
    });
    
  3. Just if you haven't an admin js, you can it like this:

    app/design/adminhtml/default/default/layout/local.xml

    <?xml version="1.0"?>
    <layout version="0.1.0">
        <adminhtml_system_config_edit>
            <reference name="head">
                <action method="addJs"><script>admin/my-custom-admin.js</script></action>
            </reference>
        </adminhtml_system_config_edit>
    </layout>
    
  4. js/admin/my-custom-admin.js

    //put the content of the setp 2
    

Important: In step 2 you have to change the id's #sd_general_general_checkall, #sd_general_general_serviceOptions with the yours. if you encounter difficulties, post your full xml.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top