3

I have added select option SFTP host with values production, sandbox in my system.xml file of custom extenstion. There is one text field SFTP port in system.xml. I want to set the text field value on change of selection.

If I select production , then port value = 22 If I select sandbox , then port value = 21

<ftphost translate="label">
<label>SFTP host</label>
<frontend_type>select</frontend_type>
<source_model>gb/system_config_source_sftp</source_model>
<sort_order>60</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</ftphost>
<ftpport translate="label">
 <label>SFTP port</label>
 <frontend_type>text</frontend_type>
 <sort_order>70</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </ftpport>

new system.xml

<liveenvironment translate="label">
 <label>Live environment</label>
 <frontend_type>select</frontend_type>
 <source_model>adminhtml/system_config_source_yesno</source_model>
 <comment><model>gb_gbgsp/system_config_source_sftpcomment</model>
 </comment>
 <sort_order>1</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </liveenvironment>

comment.php

<?php 
class gb_gbgsp_Model_Adminhtml_System_Config_Source_Sftpcomment extends Mage_Core_Model_Config_Data
{
 public function getCommentText(Mage_Core_Model_Config_Element $element, $currentValue)
 {
 $result = "<script type='text/javascript'> 
 function init_comment()
 {
 $('#carriers_gbgsp_liveenvironment').observe('change', function(){
 var field_value = $('#carriers_gbgsp_liveenvironment').getValue();
 alert(field_value);
 });
 }
 document.observe('dom:loaded', function(){init_comment();});
 </script>";
 return $result;
 }
}
dotancohen
1,1306 silver badges21 bronze badges
asked Sep 30, 2015 at 11:10

2 Answers 2

0

you can add your js through comment model

<ftphost translate="label">
 <label>SFTP host</label>
 <frontend_type>select</frontend_type>
 <source_model>gb/system_config_source_sftp</source_model>
 <comment> <![CDATA[<script type='text/javascript'> 
 function init_comment()
 {
 $('yourslelectid').observe('change', function(){
 var field_value = $('yourslelectid').getValue();
 //add your condition here
 });
 }
 document.observe('dom:loaded', function(){init_comment();});
 </script>]]
 </comment>
 <sort_order>60</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </ftphost>
answered Sep 30, 2015 at 11:38
11
  • I tried this but nothing happen Commented Oct 1, 2015 at 11:21
  • did you add your field #ids in this function? Commented Oct 1, 2015 at 11:25
  • Yup. I have created class comment.php in my model folder and integrated my selectbox id in it. Commented Oct 1, 2015 at 11:37
  • did it try alert in function it is working or not? Commented Oct 1, 2015 at 11:42
  • I tried it but no luck. I believes it doesn't get called Commented Oct 1, 2015 at 11:43
0
<liveenvironment translate="label">
 <label>Live environment</label>
 <frontend_type>select</frontend_type>
 <source_model>adminhtml/system_config_source_yesno</source_model>
 <comment><![CDATA[
 <script type='text/javascript'> 
 function init_comment()
 {
 $('carriers_gbgsp_liveenvironment').observe('change', function(){
 var field_value = $('carriers_gbgsp_liveenvironment').getValue();
 alert(field_value);
 });
 }
 document.observe('dom:loaded', function(){init_comment();});
 </script>
 ]]> </comment>
 <sort_order>1</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </liveenvironment>
answered Oct 1, 2015 at 12:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.