How to add iff statement to details view

Hi,
Iā€™m looking at detailviewdefs for invoices and I would like to make if statements so that certain panels show up if at certain sales stages; (much like a shopping transaction on an e-commerce website).

For example, an enquiry would start at the first stage and only show basic info/first panel, and then the user clicks a next button on the bottom left and the basic info is hidden and the next section is shown.

I roughly know how to code the logic but how would I fit this into the arrays?
Thanks

Would it not be better to do this with JavaScript? For example have a all the panels and fields showing as they are then add JavaScript to the view to hide panels. When certain options or buttons are clicked the hidden panels could be shown or hidden etcā€¦ I donā€™t think its possible to do it the way you are suggesting at least not without major reworking of the entire module.

Ok sounds good thanks, but which files would I edit to implement this javascript function?

You include a custom JavaScript file into the view or you can write the code directly into the view.

see here: http://sugarmods.co.uk/adding-custom-javascript-to-a-view-in-sugarcrm/

If you know Jquery this should be relatively easy for you to implement.

So am I able to copy this code directly just into the bottom of the detailviewdefs.php and edit it and it will fire?

No! You obviously didnā€™t read the link I gave you properly.

As I said in the link I gave you. You can add a custom js file to the includes section of the editview defs or you can create a new view and echo the JavaScript out in php directly into the view.

You cannot add if statements or add JavaScript directly to the ediviewdefs! At least not in the way you are trying to do it.

I did read the link but you also said in your 2nd post:
ā€œor you can write the code directly into the view.ā€

Either way it isnā€™t working when I reference the js file.

The view is not the editviewdefs you have to create a view.edit file as I said in the link!

Referencing the js file is best way to go about it. And if its not working then you have made a mistake somewhere along the line.

Attach your custom editviewdefs.php and the js file.

Well you can see where the confusion came from.

Iā€™ve got it to work now thanks.

Now it stopped working completely randomly and wonā€™t do anything:

var current_status = document.getElementById(ā€œstatusā€);
if(current_status.value == ā€œPaidā€){
document.getElementById(ā€œdetailpanel_2ā€).style.display=ā€œnoneā€;
document.getElementById(ā€œdetailpanel_3ā€).style.display=ā€œnoneā€;}

ā€˜includesā€™ =>
array (
0 =>
array (
ā€˜fileā€™ => ā€˜custom/modules/AOS_Invoices/Stages.jsā€™, //call for the js file
),
),

Ensure you have developer mode enabled in the admin panel. Comment out your JavaScript and just put alert('works); Refresh the page and if the popup appears then the js file is referenced properly and the issue is with your code.

Thanks, got it to work eventually.
Is there a possibility of using javascript to alter the selected item in a drop down menu?

I.e. Could I have a next button that when clicked changes the status of an invoice from ā€˜Stage 1ā€™ to ā€˜Stage 2ā€™?
Thanks

Yes of course. Thats easy!