Created
September 12, 2021 20:40
-
-
Save adriangohjw/331234f164b45b39ed6338fecb96115a to your computer and use it in GitHub Desktop.
Conversational Form in 65 lines of code - Here's how I built it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldset cf-questions="What is your favourite band?"> | |
<label for="fav-band-forests">Forests | |
<input type="radio" name="fav-band" id="fav-band-forests" value="Forests" cf-image="/assets/fav-band/forests.jpg"> | |
</label> | |
<label for="fav-band-tmp">TMP | |
<input type="radio" name="fav-band" id="fav-band-tmp" value="TMP" cf-image="/assets/fav-band/tmp.jpg"> | |
</label> | |
<label for="fav-band-xfr">Xingfoo&Roy | |
<input type="radio" name="fav-band" id="fav-band-xfr" value="Xingfoo&Roy" cf-image="/assets/fav-band/xfr.jpg"> | |
</label> | |
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select cf-conditional-fav-band="Forests" cf-questions="What is your favourite song by <strong>{fav-band}</strong> then?" name="fav-song" multiple> | |
<option value="Kawaii Hawaii">Kawaii Hawaii</option> | |
<option value="Tamago">Tamago</option> | |
<option value="Cup of Tea">Cup of Tea</option> | |
<option value="This Town Needs Fun">This Town Needs Fun</option> | |
<option value="Who Cares, Really?">Who Cares, Really?</option> | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function() { | |
var conversationalForm = window.cf.ConversationalForm.startTheConversation({ | |
formEl: document.getElementById("my-form-element"), | |
userImage: "/assets/userImage.jpg", | |
robotImage: "/assets/robotImage.jpeg", | |
submitCallback: function() { ... } | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/space10-community/conversational-form@1.0.1/dist/conversational-form.min.js" crossorigin></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" name="name" cf-questions="What is your name?" required /> | |
<cf-robot-message cf-questions="Eww, what kind of name is <strong>{name}</strong>. Oh well, anyway..."></cf-robot-message> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://adriangohjw.github.io/posts/2021/09/12/building-conversational-form.html