Copy link to clipboard
Copied
I have a field or two that has a few house cleaning chores to do in order to increase functionality and eliminate some confusion for the user but I have gone about as far as I can with it.
First, I have a Yes/No radio group that will conditionally show a date field. This part works for all intents and purposes, but.....
If No is selected the datefield is not visible, if yes is selected the date field is visible.
If the user selects 'yes' and fills in the datefield and then proceeds to the next page and then hits the back button the 'Yes' is still selected but the date field with their date entered is not visible, but if the radio button is re-selected the field will become visible with the date that they entered. How do I make it so that no matter what that if the 'Yes' option is selected the datefield will be visible?
Heres my current code at the moment:
<script type = "text/javascript">
<!--
function hide(x) {
document.getElementById(x).style.visibility="hidden";
}
function show(x) {
document.getElementById(x).style.visibility="visible";
}
//-->
</script>
<cfinput type="radio" id="sendbcastemail2" name="sendbcastemail" onClick="hide('showhidesendbcastemail')" value="No" checked="#sendbcastemail2_Checked#">No
<cfinput type="radio" id="sendbcastemail1" name="sendbcastemail" onClick="show('showhidesendbcastemail')" value="Yes" checked="#sendbcastemail1_Checked#">Yes
<cfdiv id="showhidesendbcastemail" style="visibility:#showhidesendbcastemaildate#">Select date:<br>
<cfinput type="datefield" name="sendbcastemaildate" value="#getLastedit.sendbcastemaildate#" validate="date" message="Enter a Valid Date">
Next, how do I make the datefield conditionally required.
If the user selects 'No' the field is not required, but if 'Yes' is selected the datefield is required?
TIA for any assistance.
Copy link to clipboard
Copied
The browser behaviour when user hits back button is entirely browser dependent and there is very little you can do about it, you might want to look at HTML cache related pragmas and JavaScript browser history handling...
"how do I make the datefield conditionally required"
Do you want to validate it on client or server?
If you show/hide the fields on client side as and when required and submit a form, the hidden fields will NOT be submitted to the server (AFAIR), so on the server you can just check when the fields are present in form scope...
Copy link to clipboard
Copied
I was hoping to be able to use the 'required' attribute like I am already using on a few other fields.
Basically, If the 'yes' radio button is selected then I want the datefield required.
Radio button
Yes = Required datefied
No= Not required datefield
Copy link to clipboard
Copied
You can write some js for that, but it's not likely to solve the problem in the OP.
Copy link to clipboard
Copied
"Required" attribute is NOT a standard HTML attribute, it is implemented by CF with JavaScript.
There was better implementation of the same with HTML <input /> elements, so you can try that, just change required attribute of <input />(not <CFinput />) elements and check all in your own JavaScript validation...