AnsweredAssumed Answered

HOW TO: Changing Dropdown value after button click

Question asked by Dev Student on Jul 20, 2016
Latest reply on Aug 1, 2016 by André Lopes

I'm trying to change the value of a dropdown list via a click of a button, I'm using SugarCRM CE 6.5, and here's the problem I encoutered:I'm trying to change the value of a dropdown list via a click of a button, I'm using SugarCRM CE 6.5, and here's the problem I encoutered:

Error - 3.png

 

And here's my code below:

-- detailviewdefs.php

<?php

$module_name = 'UA_Quotes';

$viewdefs [$module_name] =

array (

  'DetailView' =>

  array (

    'templateMeta' =>

    array (

      'include' =>

       array (

        0 =>

        array (

          'file' =>

          'custom/modules/UA_Quotes/JS/clickPayment.js',

          ),

        ),

      'form' =>

      array (

        'closeFormBeforeCustomButtons' => true,

        'buttons' =>

        array (

          0 => 'EDIT', 

          1 => 'DELETE',

          2 =>

          array (

            'customCode' => '{$Monthly_Payment}',

          ),

        ),

        'footerTpl' => 'modules/UA_Quotes/tpls/DetailViewFooter.tpl',

      ),

      'maxColumns' => '2',

      'widths' =>

      array (

        0 =>

        array (

          'label' => '10',

          'field' => '30',

        ),

        1 =>

        array (

          'label' => '10',

          'field' => '30',

        ),

      ),

      'useTabs' => false,

      'tabDefs' =>

      array (

        'LBL_EDITVIEW_PANEL2' =>

        array (

          'newTab' => false,

          'panelDefault' => 'expanded',

        ),

      ),

    ),

    'panels' =>

    array (

      'lbl_editview_panel2' =>

      array (

        0 =>

        array (

          0 => 'name',

          1 =>

          array (

            'name' => 'ua_contracts_ua_quotes_1_name',

          ),

        ),

        1 =>

        array (

          0 =>

          array (

            'name' => 'monthlystart_c',

            'label' => 'LBL_MONTHLYSTART',

          ),

          1 =>

          array (

            'name' => 'quote_stage',

            'studio' => 'visible',

            'label' => 'LBL_QUOTE_STAGE',

          ),

        ),

        2 =>

        array (

          0 =>

          array (

            'name' => 'monthlydeadline_c',

            'label' => 'LBL_MONTHLYDEADLINE',

          ),

        ),

      ),

    ),

  ),

);

?>

 

-- view.detail.php

<?php

require_once('include/MVC/View/views/view.detail.php');

class UA_QuotesViewDetail extends ViewDetail

{

    public function __construct()

    {

        parent::ViewDetail();

    }

 

 

    public function display()

    {

        echo '<script type="text/javascript" src="custom/modules/UA_Quotes/js/clickPayment.js"></script>';

        $groups = $this->bean->Get_Products($this->bean->id, true);

        $this->ss->assign('GROUPS', $groups);

 

 

        $this->ss->assign('NET_TOTAL', currency_format_number($this->bean->net_total_amount));

        $this->ss->assign('TOTAL', currency_format_number($this->bean->total_amount));

        $this->ss->assign('Monthly_Payment', '<input type="button" onclick="GetPayment();" value="Monthly Payment"/>');

        /*

        $this->dv->ss->assign('Monthly_Payment', '<input type="button"

        onclick="alert(\'How to change status :(\')" value="Monthly Payment"/>');*/

      

        parent::display();

    }

}

 

-- clickPayment.js

    function GetPayment(){

   

    var record = $("#record").val();

    // var pathArray = window.location.href.split("=");

    var fdata = { 'record':record };  

    // console.log(pathArray[3]," - your Record ID");

    $.ajax({

                        type: 'POST',                

                        url: "custom/modules/UA_Quotes/js/changestatus.php?&fdata="+fdata+"",

                        data: fdata, //{recordID: pathArray[3]},

                        dataType: 'html',

                        async: false,

                        error: function(resp){},

                        success: function(resp){

                            location.reload(true);

                        }                    

                        /*  success:function(fdata){                    

                            console.log("Customer Status Change");

                             location.reload(true);       

                        },

                        error: function(fdata) {

                            // if error occured

                            console.log(" NA ");                    

                        }   */

                    });

    }

 

-- and finally, my changestatus.php

<?php

$myrecordID = $_POST['record'];

$focus = new UA_Quotes();

$focus->retrieve($myrecordID);

$focus->quote_stage_dom = 'Paid';

?>

 

I am very sorry for the long post of codes, I've been dealing with 'em for a couple of days now, and seems to be of no luck. Any help could be appreciated! Thank you!

Outcomes