JQuery ExpressionBuilder
JQuery plugin for arithmetic expressions with intellisense
Currently v2.1.1
JQuery plugin for arithmetic expressions with intellisense
Currently v2.1.1
ExpressionBuilder is UI component to create a input for arithmetic expressions with functiuons and intellisense
Include the Javascript
and Stylesheet
files in the head of your page as following:
The fundamental use of the ExpressionBuilder could be just enabling a validation on the user input. fisrt we need to have a input
:
To setup the besic functionality, use the following javascript code:
See the besic demo here
Name | Type | Default | Description |
---|---|---|---|
variables | object[] | Array of available variables to suggest while user is typing in the expression. See below | |
expression | string | '' | Initial expression to be set into the input while generating the expression builder |
preventWrongInput | boolean | false | Helps the user to input the expression easily by preventing to input wrong caracters (limits some correct expressions to input) |
functions | object | {} | A json object with desired fuctions to support in the expression. See below |
suggestions | 'up'|'down' | 'down' | Suggestion position when the user is searching a variable or function |
Property | Type | Description |
---|---|---|
variableId | number|string |
It will be replace with the variable name in a bracket liek [32] ,
to avoid any error make sure to have a unique id for each variable
|
name | string | Searchable variable name |
value | any | To compute the expression and get the result you can pass value to each variable |
ExpressionBuilder will suggest the available variables while the user is typing part of the variable name and will replace the variable Id in a bracket as the result. See the following example:
If the varaiable name starts with a digit expressionBuilder will wrap it in brackets or user should type it in brackets like:
[1_name] + " " + LastName
See the varaible demo here
This is a flexible object you can add to expressionBuidler to support as part of the expression. Not only it will suggest it while user is typing a part of the function name, but also it shows the function signature to help user to avoid wrong syntaxes. Also, expresssionBuilder will use the same function when you run the expression.
In the following example we define to simple Add
and Sub
function to the expressionBuilder
and you can see the runing example in the demo page.