Wednesday, June 26, 2013

Dependable Required Field




e.g.: 
       My Module Name : Desner
       Field                   : desnerStatus_c ( DropDown ) (Values :  nitin, blog, spot, nrsd)



Condition : if i select nrsd from desnerStatus_c dropdown want description required else remove validation.


Step1: Copy or make path like Sugarcrm/custom/modules/Desner/views/view.edit.php

Step2: copy below code in view.edit.php

<?php
require_once('include/MVC/View/views/view.edit.php');
class DesnerViewEdit extends ViewEdit {
    public function __construct() {
        parent::ViewEdit();
        $this->useForSubpanel = true; 
        $this->useModuleQuickCreateTemplate = true; 
    }
    function display() {
        global $mod_strings;
        $jsscript = <<<EOQ

                   <script>
                      
       $('#desnerStatus_c').change(function() {
            makerequired(); 
                       });
 function makerequired()
  {
        var status = $('#desnerStatus_c').val(); 
       if(status == 'nrsd'){                     addToValidate('EditView','description','varchar',true,'{$mod_strings['LBL_DESCRIPTION']}');                           $('#description_label').html('{$mod_strings['LBL_DESCRIPTION']}: <font color="red">*</font>'); 
                            }
       else{
          removeFromValidate('EditView','description');                       
                        $('#description_label').html('{$mod_strings['LBL_DESCRIPTION']}: '); 
                            }
         }
     makerequired(); 
    </script>
EOQ;
        parent::display();
        echo $jsscript;     
    }

}



Note:

  •         It is tested on SugarCRM 6.5 and above
  •         For another version that not supported JQuery add one line after <<<EOQ
         <script src="http://code.jquery.com/jquery-1.9.1.js"></script>




Step 3 : Any Query Please Make comment




                                                       



No comments:

Ad