Due to my near complete lack of experience with JS i seem to be encountering problems
I am trying to create an integer field called deposit that autofills depending on what is selected in the sales stage.
I have created a dropdown called Deposit_autofil (which is essentially a duplicate of the sales_probability_dom
I have created an integer fields called deposit1_c
I have ammended <sugar-root>/modules/Opportunities/views/view.edit.php as follows
Code:
require_once('include/MVC/View/views/view.edit.php');
class OpportunitiesViewEdit extends ViewEdit {
function OpportunitiesViewEdit(){
parent::ViewEdit();
$this->useForSubpanel = true;
}
function display() {
global $app_list_strings;
$json = getJSONobj();
$Dep_array = $json->encode($app_list_strings['Deposit_autofil']);
$prob_array = $json->encode($app_list_strings['sales_probability_dom']);
$prePopProb = '';
$prePopDep = '';
if(empty($this->bean->id)) $prePopProb = 'document.getElementsByName(\'sales_stage\')[0].onchange();';
if(empty($this->bean->id)) $prePopDep = 'document.getElementsByName(\'sales_stage\')[0].onchange();';
$probability_script=<<<EOQ
<script>
prob_array = $prob_array;
document.getElementsByName('sales_stage')[0].onchange = function() {
if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && prob_array[document.getElementsByName('sales_stage')$
document.getElementsByName('probability')[0].value = prob_array[document.getElementsByName('sales_stage')[0].value];
}
};
$prePopProb
</script>
EOQ;
$this->ss->assign('PROBABILITY_SCRIPT', $probability_script);
$deposit_script=<<<EOQ
<script>
dep_array = $Dep_array;
document.getElementsByName('sales_stage')[0].onchange = function() {
if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && dep_array[document.getElementsByName('sales_stage')$
document.getElementsByName('deposit1_c')[0].value = dep_array[document.getElementsByName('sales_stage')[0].value];
}
};
$prePopDep
</script>
EOQ;
$this->ss->assign('DEPOSIT_SCRIPT', $deposit_script);
parent::display();
}
}
?> And ammended <sugar-root>/modules/Opportunities/metadata/editviewdefs.php like this
Code:
$viewdefs['Opportunities']['EditView'] = array(
'templateMeta' => array('maxColumns' => '2',
'widths' => array(
array('label' => '10', 'field' => '30'),
array('label' => '10', 'field' => '30')
),
'javascript' => '{$PROBABILITY_SCRIPT}',
'javascript' => '{$DEPOSIT_SCRIPT}',
),
'panels' =>array (
'default' =>
array (
array (
array('name'=>'name', 'displayParams'=>array('required'=>true)),
'currency_id',
),
array (
'account_name',
array( 'name'=>'amount','displayParams'=>array('required'=>true)),
),
array (
'opportunity_type',
array('name'=>'date_closed', 'displayParams'=>array('required'=>true)),
),
array (
'lead_source',
'next_step',
),
array (
'campaign_name',
),
array (
array('name'=>'sales_stage', 'displayParams'=>array('required'=>true)),
),
array (
'assigned_user_name',
'probability',
'deposit1_c',
),
array (
'description',
),
),
)
);
?> Nothing seems to be broken but my field deposit field in the edit view still dosnt autofill.....I imagine its due to some completely obvious idiotic mistake so feel free to mock
but any help would be greatly appreciated.
Bookmarks