jrsinclair / jquery-dependent-questions Goto Github PK
View Code? Open in Web Editor NEWA jQuery plugin for showing/hiding form elements based on the answers to previous questions.
License: MIT License
A jQuery plugin for showing/hiding form elements based on the answers to previous questions.
License: MIT License
How do I configure this auto-load for a drop-down menu?
<form action="?" id="myform">
<fieldset class="form-question">
<legend>What type of event are you planning?
<div class="general-event-question">
<select name="eventType" id="eventTypeDropDown">
<option value="wedding" name="eventType" id="isAWeddingEvent">A Wedding
<option value="general" name="eventType" id="isAGeneralEvent" for="eventTypeDropDown">
<<abel for="isAGeneralEvent">A General Event
</option>
</select>
</div>
</fieldset>
<fieldset data-depends-on="eventType=isAGeneralEvent">
<p>hi
Thank you!
Hey,
lots of frameworks generate an <input type="hidden" name="check" value="default">
directly before the checkbox when using a checkbox. This leads to a problem with this plugin: it assumes that the checkbox isn't a multi plugin and its value is always the default value.
I did the following patch to get it working:
@@ -88,16 +88,19 @@
elType = el.attr("type");
multi = contains(multiInputs, elType);
- if (!multi) { return el.val(); }
+ if (!multi && (el.length < 1 || $(el[0]).attr('type') != 'hidden')) { return el.val(); }
if (elType === "radio") { return el.filter(":checked").val(); }
- if (elType === "checkbox") {
- checkVals = $.map(el.filter(":checked"), function (checkbox) {
- return $(checkbox).val();
- });
- return checkVals;
+ checkVals = $.map(el.filter(":checked"), function (checkbox) {
+ return $(checkbox).val();
+ });
+
+ if($(el[0]).attr("type") == 'hidden' && checkVals.length === 0) {
+ checkVals = [$(el[0]).val()];
}
+
+ return checkVals;
}
// Event handler for when a toggling element changes value.
This is not the most beautiful solution, but at least it works.
Hi @jrsinclair ,
I was impressed by your website when I was landed on it by Google search, so I'm curious what's the theme/tool/lib you use for rendering it .. Or is it written by yourself ?
Also, would you like to share it or make it open sourced ? I guess people will like it
Cheers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.