In order to deal with validation of fields with multiple optional checkboxes I used webshims polyfill.
The form has checkboxes that hide/unhide sections of the form.
Initial task was to only validate/require the hidden sections if they became visible.
My initial idea was - I could use built in features of webshims polyfill to only require a hidden field if the checkbox associated with making that field visible was checked.
Problem #1: However, some of the hidden sections include these multi-checkbox type fields that need validation. How do I get these fields to make use of webshims' data-grouprequired="" feature so I can validate these multi-checkbox fields?
Problem #2: Finally, there is one hidden section (Registries) with 5 input text fields - the end user only needs to fill in at least one of these fields. How do I make it so that when this hidden section becomes visible, only a minimum of one of the 5 fields is required in order to validate the form?
Alternatively, if there is a better solution I'd love to learn. I am very new to this.
Here's the relevant code from the form:
<script>
webshim.setOptions('forms', {
lazyCustomMessages: true,
addValidators: true
});
webshim.polyfill('forms forms-ext');
</script>
<script>
function addTableRow() {
var $tableRow = $('tr.model-row:first-child');
var $clonedRow = $tableRow.clone().show();
$('#stmember').append($clonedRow);
}
function myDeleteFunction() {
var $memberTRs = $('tr', '#stmember');
// If rowcount === 1, hide first row, don't remove it!!
var rowCount = $memberTRs.length;
if (rowCount === 1) {
$('tr.model-row:first-child').hide();
return;
}
$memberTRs.last().remove();
}
jQuery(function() {
$('#delete').click(function() {
myDeleteFunction();
});
$('#add').click(function() {
addTableRow();
});
});
</script>
<script type="text/javascript">
function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
</script>
<body>
<form method="post" action="mailto:you@example.com" enctype="text/plain">
<div class="row 50%">
<div class="12u">
Which of the following would you like to do with your specified patient population? Check all that apply.<br />
<ul class="list">
<li><input type="checkbox" id="recruit" name="todo" value="1" data-grouprequired="" onclick="showMe('div1', this)"> Recruitment for research</li>
<li><input type="checkbox" id="edc" name="todo" value="2" onclick="showMe('div2', this)"> Electronic Data Capture</li>
<li><input type="checkbox" name="registry" value="3" onclick="showMe('div3', this)"> Registry</li>
<li><input type="checkbox" name="dextract" value="4" onclick="showMe('div4', this)"> Data Extraction</li>
<li><input type="checkbox" name="ptpop" value="5">Estimate of number of patients in target population</li>
</ul>
</div>
</div>
<div id="div1" style="display:none">
<div class="row 50%">
<div class="12u">
<h3><strong>Recruitment</strong></h3>
What methods would you like to use for patient recruitment? Check all that apply.<br />
<ul class="list">
<li><input type="checkbox" name="vehicle" value="Bike"> Patient Notification Through MyChart</li>
<li><input type="checkbox" name="vehicle" value="Car"> Study Team Member Notification When Appropriate Patient Checks In</li>
<li><input type="checkbox" name="vehicle" value="Car"> Provider Notification During Patient Encounter</li>
</ul>
</div>
</div>
</div>
<div id="div2" style="display:none">
<h3><strong>Electronic Data Capture</strong></h3>
<div class="row 50%">
<div class="6u 12u (mobile)">
How would you like to capture data on your patient population? Check all that apply.<br />
<ul class="list" style="margin-bottom: 0px; padding-bottom: 0px;">
<li><input type="checkbox" name="vehicle" value="Bike"> Patient entry through MyChart</li>
<li><input type="checkbox" name="vehicle" value="Car"> Patient entry through Welcome</li>
<li><input type="checkbox" name="vehicle" value="Car"> Patient entry through REDCap</li>
<li><input type="checkbox" name="vehicle" value="Car"> Clinician entry through EPIC</li>
<li><input type="checkbox" name="vehicle" value="Car"> Clinician entry through REDCap</li>
<li><input type="checkbox" name="vehicle" value="Car"> MHi-GO (Mobile Application)</li>
</ul>
</div>
<div class="6u 12u(mobile)">
Where would you like the data delivered to? (Server name, share name, or JHBox, Enterprise NAS, etc.)
<input name="subname" type="text" data-dependent-validation='{"from": "edc", "prop": "required"}' />
</div>
</div>
<div class="row 50%">
<div class="6u 12u(mobile)">
In what format would you like to receive your data? (Excel, pipe-delimited, CSV, SQL tables)
<input name="subjhed" type="text" data-dependent-validation='{"from": "edc", "prop": "required"}' />
</div>
<div class="6u 12u(mobile)">
Would you like the data visualized and if so how? (Graphs, tables, diagrams, other)
<input name="subemail" type="text" data-dependent-validation='{"from": "edc", "prop": "required"}' />
</div>
</div>
</div>
<div id="div3" style="display:none">
<div class="row 50%">
<h3><strong>Registries</strong></h3>
</div>
<h3 class="quest-header"><strong>What information and/or metrics of your patient population would you like to track over time?</strong></h3>
Please specify if applicable:
<div class="row 50%">
<div class="6u 12u(mobile)">
Diagnoses:
<input name="subjhed" type="text" />
</div>
<div class="6u 12u(mobile)">
Problem List:
<input name="subemail" type="text" />
</div>
</div>
<div class="row 50%">
<div class="6u 12u(mobile)">
Medications:
<input name="subjhed" type="text" />
</div>
<div class="6u 12u(mobile)">
Labs:
<input name="subemail" type="text" />
</div>
</div>
<div class="row 50%">
<div class="6u 12u(mobile)">
Other:
<input name="subjhed" type="text" />
</div>
</div>
</div>
<div id="div4" style="display:none">
<div class="row 50%">
<div class="12u">
<h3><strong>Data Extraction</strong></h3>
What data would you like to extract?
<textarea name="description" data-dependent-validation='{"from": "dextract", "prop": "required"}' ></textarea>
</div>
</div>
<div class="row 50%">
<div class="6u 12u(mobile)">
Where would you like the data delivered to? (Server name, share name, or JHBox, Enterprise NAS, etc.)
<input name="subemail" type="text" data-dependent-validation='{"from": "dextract", "prop": "required"}' />
</div>
<div class="6u 12u(mobile)">
In what format would you like to receive your data? (Excel, pipe-delimited, CSV, SQL tables)
<input name="subjhed" type="text" data-dependent-validation='{"from": "dextract", "prop": "required"}' />
</div>
</div>
</div
<div class="row 50%">
<div class="12u">
<center>
<ul class="actions">
<li><input type="submit" value="Submit Request" /></li>
<li><input type="submit" value="Save & Continue Later" /></li>
<li><input type="reset" value="Clear form" /></li>
</ul>
</center>
</div>
</div>
</form>
Aucun commentaire:
Enregistrer un commentaire