How to select all fields in multi-select on single click in magento 1.9
-
26-01-2021 - |
Frage
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 !
Lösung
You can do with xml, js
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>
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); } });
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>
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.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange