Create Dynamic Field

So it turns out there was a view.edit.php file in the file location you specified I have tried to modify the file by putting the below code below the function display(){ line however when i run a rebuild and repair and I try to create a new invoice I am unable to access the create invoices area of my crm. Please see below for my php code.

<?php
require_once('include/MVC/View/views/view.edit.php');

class AOS_InvoicesViewEdit extends ViewEdit{
function AOS_InvoicesViewEdit(){
parent::ViewEdit();
}

function display(){
	public function display(){
        parent::display();
        $javascript = <<<'EOT'
<script type="text/javascript">
  window.onload=function(){
    function toggle_extra_field() {
      if(xx_extra_field.value == No) {
        document.querySelector('div[data-label="LBL_DEFECT_NUMBER"]').style.display='none';
        document.querySelector('div[field="defect_number_c"]').style.display='none';
      }
      if(xx_extra_field.value == Yes) {
        document.querySelector('div[data-label="LBL_DEFECT_NUMBER"]').style.display='';
        document.querySelector('div[field="defect_number_c"]').style.display='';
        var xx_extra_field_sub = document.getElementById('defect_number_c');
        xx_extra_field_sub.value = '';
      }
    }
    var xx_extra_field = document.getElementById('defect_number_required_c');
    toggle_extra_field();
    xx_extra_field.addEventListener('change', toggle_extra_field, false);
  }
</script>
EOT;
      echo $javascript;
      exit;
     }
	
echo '<script type="text/javascript" src="custom/include/javascript/showhide.js"></script>';
parent::display();
}
}
?>

(Please use the Forum’s code tags when pasting code, this makes sure some brackets don’t get deleted, and makes it more readable.)

The base class already extends ViewEdit:

modules/AOS_Invoices/views/view.edit.php:8:class AOS_InvoicesViewEdit extends ViewEdit

So if you’re adding an additional customization, and still want to keep that code, you should do an extension of the extension, so your code would be something like:

class My_Custom_AOS_InvoicesViewEdit extends AOS_InvoicesViewEdit {

Keep an eye on your PHP error log when doing this sort of customization, so you catch any FATALs from broken code, this will save you a lot of time. This is defined in your php.ini, usually it’s called php_errors.log