01e9 / johan-formula

Simple formula builder

Home Page:https://01e9.github.io/johan-formula/demo.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Johan Formula

Simple, nice looking formula builder.

Demo

Usage

<div class="formula"></div>
<input type="hidden" name="formula"> 
$('.formula').johanFormula({
    // Save JSON in this input
    $output: $('input[name="formula"]'),

    // Define new element types
    elementTypes: {
        // Note: All methods are optional
        typeName: {
            init: function () {
                // [] - if element is a container (can hold other elements)
                // null - if element can't hold other elements
                this.elements = null;
            },
            // Check if user input matches your value format
            match: function(value) {
                return 'SpecialValueFormat' === value;
            },
            // Custom render
            render: function() {
                this.$el.text('~'+ this.value +'~');
            },
            // Check if the element is valid and its neighbors are supported
            isValid: function(prevEl, nextEl) {
                // ... see plugin code
            },
            // After the element has been added after user input
            afterAdd: function () {},
            // Before element remove from parent.elements[] and $el.remove()
            onDestroy: function() {}
        }
    }
});

About

Simple formula builder

https://01e9.github.io/johan-formula/demo.html


Languages

Language:JavaScript 86.2%Language:HTML 8.9%Language:CSS 4.9%