Based off a visit reason type I want the "Special Diet" pre selected option to be a specific option on the menu. It defaults to "general diet" no matter the visit type.
The correct menus pop up so the if then statement is working, but its defaulting incorrectly.
{formmenu: default=Visit Reason; Wellness; Health Certificate; Recheck; Acute Diarrhea; Chronic Diarrhea; Sick; Tele-Health; name=Main Visit Reason; cols=30}{if: main visit reason
= "Wellness" or main visit reason
= "Health Certificate" or main visit reason
= "Tele-Health" or main visit reason
= "Recheck"}{formmenu: default=General Diet; Weight Loss; Bland; IBD; Low Fat; Allergy; Atopy; Consider Diet Trial; Joint; Kidney; Urinary; Cardiac; Hepatic; Diabetic; Vegetarian; Calming; name=Special Diet; cols=16.5}{elseif: main visit reason
= "Acute Diarrhea" or main visit reason
= "Chronic Diarrhea"}{formmenu: default=Bland; Low Fat; IBD; IBD (Puppy); General Diet; name=Special Diet; cols=22.5}{elseif: main visit reason
= "Sick"}{formmenu: default=Bland; IBD; Low Fat; Not Eating; Current Diet; General Diet; name=Special Diet; cols=22.5}{endif: trim=yes}{if: Special Diet
= "General Diet"}
{import: @dietgeneral}{elseif: Special Diet
= "Weight Loss"}
{import: @weightloss}{elseif: Special Diet
= "Allergy"}
{import: @dietallergy}{elseif: Special Diet
= "Atopy"}
{import: @dietatopy}{elseif: Special Diet
= "Consider Diet Trial"}
{import: @considerdiet}{elseif: Special Diet
= "Bland"}
{import: @dietbland}{elseif: Special Diet
= "IBD"}
{import: @dietibd}{elseif: Special Diet
= "Low Fat"}
{import: @dietlowfat}{elseif: Special Diet
= "Joint"}
{import: @dietjoint}
Recommend softened kibble with water or wet food for the time being.{endif: trim=yes}
Hi @Geoff_Kraabel, welcome back to the forum. 
The problem is that all form menus have the same name "Special Diet
", which causes the first one's default to override the others. You can give each form menu a different name, then conditionally set the Special Diet
variable to the selected value from the appropriate menu as follows:
{=`Special Diet`}
{formmenu: default=Visit Reason; Wellness; Health Certificate; Recheck; Acute Diarrhea; Chronic Diarrhea; Sick; Tele-Health; name=Main Visit Reason; cols=30}{if: `main visit reason` = "Wellness" or `main visit reason` = "Health Certificate" or `main visit reason` = "Tele-Health" or `main visit reason` = "Recheck"}{formmenu: default=General Diet; Weight Loss; Bland; IBD; Low Fat; Allergy; Atopy; Consider Diet Trial; Joint; Kidney; Urinary; Cardiac; Hepatic; Diabetic; Vegetarian; Calming; name=Special Diet 1; cols=16.5}{`Special Diet`=`Special Diet 1`}{elseif: `main visit reason` = "Acute Diarrhea" or `main visit reason` = "Chronic Diarrhea"}{formmenu: default=Bland; Low Fat; IBD; IBD (Puppy); General Diet; name=Special Diet 2; cols=22.5}{`Special Diet`=`Special Diet 2`}{elseif: `main visit reason` = "Sick"}{formmenu: default=Bland; IBD; Low Fat; Not Eating; Current Diet; General Diet; name=Special Diet 3; cols=22.5}{`Special Diet`=`Special Diet 3`}{else}{`Special Diet`=""}{endif: trim=yes}{if: `Special Diet` = "General Diet"}
{import: @dietgeneral}{elseif: `Special Diet` = "Weight Loss"}
{import: @weightloss}{elseif: `Special Diet` = "Allergy"}
{import: @dietallergy}{elseif: `Special Diet` = "Atopy"}
{import: @dietatopy}{elseif: `Special Diet` = "Consider Diet Trial"}
{import: @considerdiet}{elseif: `Special Diet` = "Bland"}
{import: @dietbland}{elseif: `Special Diet` = "IBD"}
{import: @dietibd}{elseif: `Special Diet` = "Low Fat"}
{import: @dietlowfat}{elseif: `Special Diet` = "Joint"}
{import: @dietjoint}
Recommend softened kibble with water or wet food for the time being.{endif: trim=yes}
Let me know if that helps.
That does make sense but then makes the out put harder/more complex.
I named them all special diet so that the output list is simple and you only need to list the diet types once, rather than 20 different times.
I just thought since the menu is in the if statement that menu would not be triggered
Is there anyway to make it so the menu is hidden if not right visit reason?
Using the same name Special Diet
for all menus, even with hiding irrelevant options, creates a persistence issue. When you switch from one Visit Reason
to another, the Special Diet
variable retains its previous value, which may no longer be applicable to the new visit type. This requires additional logic to handle default selection resets for each visit type.
For instance, if you select Visit Reason
as Wellness
and choose Special Diet
as Vegetarian
, then switch the Visit Reason
to Sick
, the Special Diet
value remains Vegetarian
even though it's not relevant for sick visits. You'd need extra logic to clear this value and set the appropriate default for the new visit type.
What would that logic look like? Is there a practical way to implement that?
@Geoff_Kraabel Here's an example of that logic:
{formmenu: default=Visit Reason; Wellness; Health Certificate; Recheck; Acute Diarrhea; Chronic Diarrhea; Sick; Tele-Health; name=Main Visit Reason; cols=30}
{if: `main visit reason` = "Wellness" or `main visit reason` = "Health Certificate" or `main visit reason` = "Tele-Health" or `main visit reason` = "Recheck"}
{options=["General Diet", "Weight Loss", "Bland", "IBD", "Low Fat", "Allergy", "Atopy", "Consider Diet Trial", "Joint", "Kidney", "Urinary", "Cardiac","Hepatic", "Diabetic", "Vegetarian", "Calming"]}
{elseif: `main visit reason` = "Acute Diarrhea" or `main visit reason` = "Chronic Diarrhea"}
{options=["Bland", "Low Fat", "IBD", "IBD (Puppy)", "General Diet", "name=Special Diet 2"]}
{elseif: `main visit reason` = "Sick"}
{options=["Bland", "IBD", "Low Fat", "Not Eating", "Current Diet", "General Diet"]}
{else}{options=""}{endif: trim=yes}
{if: options<>""}
{formmenu: values={=options}; formatter=(value)-> value if includes(option, value) else options[1]; name=Special Diet}
{endif}
{if: `Special Diet` <> "" and not includes(options, `Special Diet`)}{`Special Diet`=options[1]}{endif}
Oh great, this is perfect. Thank you so much!
1 Like