How to Enable/Disable a Field based on user option selection

abdallanizar wrote on Saturday, April 09, 2016:

Hi guys,

Lets say I have a Yes/No option in a Form. How can I enable another field if a user chooses Yes Option and disable the field if the user chooses No Option?

Best Reagards,
Abdalla Nizar

fsgl wrote on Saturday, April 09, 2016:

Give example what precisely the user is recording in his clinical note.

Instead of describing a methology, it’s more helpful for us to understand what is the task; so that it broadens the possibility of other means to an end.

abdallanizar wrote on Sunday, April 10, 2016:

fsgl,
Please see the attached. Its the History form for the patient, I have made some modifications. What I want to achieve for example, if the users chooses No option in Diabetes, then the other field “If Yes, when? which is a date field to be grayed out”.

Regards,

Abdalla

bradymiller wrote on Monday, April 11, 2016:

Hi,

There is good news and sort of bad news on this front.

The good news:
When you are in Adminsitration->Layouts->History, click the ? at the far right of the row and it will show options to make fields conditional.

The sort of bad news:
For OpenEMR 4.2.1, this only works for the Layout Based Forms and not for the demographics or history. However, in the development codebase (thanks to fixes by Matrix), it does work for the demographics and history with these two fixes:

-brady
OpenEMR

abdallanizar wrote on Monday, April 11, 2016:

Hi Brandy,
Thank you so much, that really helped.

Reagrds,
Abdalla

abdallanizar wrote on Tuesday, April 12, 2016:

Hi Brandy,
I have updated my scripts to reflect the contributions by Matrix in Github.

interface/new/new.php
interface/new/new_comprehensive.php

library/options.inc.php
library/options.js.php

interface/patient_file/summary/demographics.php
interface/patient_file/summary/demographics_full.php

interface/patient_file/history/history.php
interface/patient_file/history/history_full.php

To test the Condition if it works I have created two fields as show in Capture-1.PGN
The Condition is shown in Capture-2.PNG.

But when I visit the history page, I get an echo shown in Capture-3.PNG.

What could be the problem, have you tested if it works properly?

Thanks and regards
Abdalla

osverdlov wrote on Wednesday, April 13, 2016:

Abdalla, Brady - we are looking into this problem.

abdallanizar wrote on Wednesday, April 13, 2016:

Hi Oleg,
Noted with thanks.

Regards,
Abdalla

sharonco wrote on Thursday, April 14, 2016:

Hi Abdalla, we just did a pull request to fix this issue. We applied the fix to use conditional fields on radio buttons.
The only thins that is still open for disscusion is the way the fields where created . When setting
Label Cols = 0 and Data Cols=0. The alert will still appear as this fields have no id.
So i suggest you change this values to 1 in the meanwhile its decided how are we going to handle that.
Have a great day!

osverdlov wrote on Thursday, April 14, 2016:

Please apply this commit:

and change Label Columns to 1 and Data Columns to 1 for “diabetes” ( as in Sharon’s screenshot).
Kindly let us know if this helps.

abdallanizar wrote on Tuesday, July 26, 2016:

Hi Sharon,
Still on this same issue, I can not get it to work as expected. The DiabeticDate field is not hidden when I choose No Radio button.
I have done a new installtion of OpenEMR 4.2.2 stable release.

Please see the screen short of my settings and advice if something needs to be changed.

abdallanizar wrote on Tuesday, July 26, 2016:

Hi Sharon,
I got it to work. I had to use all capital letters for NO. and not No. Because in the List the values are in CAPITAL LETTERS.

Thanks and regards,
Abdalla Nizar

abdallanizar wrote on Tuesday, July 26, 2016:

I think there is a small bug. When I click on the first No option it affects the rest.

abdallanizar wrote on Tuesday, July 26, 2016:

When I click on the first No option it affects the rest.