Menu

Asker JS Demo

Asker JS Demo

An elegant form implemented in JS.

Installation

Using npm :

npm i askerjs

Usage

Import the AskerJS

import Asker from "askerjs";

Initialize the form constructor with the target element.

// Get the target element the form will be rendered to.
let target = document.getElementById('AskerJS')

// Create a questions object - 
//https://anas2479.notion.site/Questions-Object-7a09a9893b6c4a4bbf163bad4c0f15ba
let questions = {
    'first-name':{ 
        text: 'What is your name?',
        type: 'text', // The type of question. 
        required: true, // Whether the user can skip this question.
        next: 'last-name' // Refrence the next question.
    },
    'last-name':{
        text: 'What is your last name?',
        type: 'text',
        required: false,
    }// If question doesn't have `next` prop, Asker will assume it's the last question.
}

// The function to execute once the form is complete.
function formComplete(data){
    console.log(data);
}

**let asker = new Asker(target, questions, formComplete);**

// Start asking with the first question.
**asker.ask(questions["first-name"]);**

new Asker() Options

Option Type Definition Docs
target (required) HTMLElement The target element the form should be rendered to.
questions (required) Object The object containing the questions Questions Object
onComplete (required) onComplete
Function to be called when the form is complete.

Questions Object

Text Input Question

Paragraph Question

Single Choice Question

Multi-choice Question

Info Screen

CSS Themes

File Upload