Table of Contents
description to be added
TODO
Via npm:
npm install netjsonconfig-editor.js
TODO
Via link script, add:
<script type="text/javascript" src="node_modules/netjsonconfig-editor.js/dist/js/bundle.js"></script>
To use the editor, include the editor within the view and create a new instance as follows:
var editor = new netjsonEditor(options);
The various options available for the editor are as below. Default values will be used for any option which is not provided.
- target: target html element where the editor content will be
stored. It should be an html input element like
<input type="text" />
or<textarea></textarea>
. Default:#netjsonconfig-area
- schema: This option receives the schema to be use to validate the
content of the editor against. This should be a schema.org valid json
schema. Default:
{}
- data: The initial content to be populated within the editor on
initialisation. This option receives a valid json object as
parameter. Default:
{}
- helpText: This option is used to set the default help text to
be diaplayed at the top center of both the advanced editor and the
basic editor. Default:
Want learn to use the advanced mode? Consult the <a href="http://netjsonconfig.openwisp.org/en/stable/general/basics.html" target="_blank">netjsonconfig documentation </a>.
- validate: This is a boolean value. if true the data within the editor will be validated against the schema else it will not be validated. Defualt: true
- onChange: this is a callback reference. This is called when the
content of the editor is changed. it is triggered wen the user edits
the netjsonconfigs. Default:
null
- jsonError: String error message to be displayed when the json
within the editor is invalid and the user tries to exit the editor.
Default:
"Json entered is invalid"
The NetjsonConfig Editor is initialised as follows:
var editor = new netjsonEditor(opts);
This returns a netjsonconfig editor object which could be used to manipulate and control the editor.
targetElement
: Reference to the target element specified when initialising the editorprops
: object containing all options used to initialise the the editorcontainer
: reference to the container of the editor within the domschema
: The current schema being used within the editor.text
: Returns the data currently being edited within the editor as a json stringjson
: Returns the data currently being edited within the editor as a json object
- params:
schema
-object
of new schema - returns:
null
- description: changes the schema being used by the editor and uses the new
schema
passed to this method
- params:
json
-object
to be used as data in the editor - return:
null
- description: changes the data in the editor and uses a new
json
object as the data
- params:
null
- return:
null
- description: brings the basic editor to focus
- params:
null
- return:
null
- description: brings the advanced json editor to focus
- params:
null
- return:
state
boolean
- description: checks whether data in the editor is valid against schema or not
- params:
event
-string
name of event to listen to,callback
-func
reference of function to be called when the event occurs - description: Use the
on
method of the editor to hook in functions to be called when certain events occur
- params:
null
- description: Use the
off
method of the editor to clear any listeners to any events set previously events
: Some of the events currently being emmitted are:- change: emmitted when data within the editor changes.
- params:
null
- description: This method can be used to destroy the editor and free up resources allocated.
First off, thanks for taking the time to read these guidelines.
Trying to follow these guidelines is important in order to minimize waste and avoid misunderstandings.
- Ensure your changes meet the Project Goals
- If you found a bug please send a failing test with a patch
- If you want to add a new feature, announce your intentions in the issue tracker
- Fork this repo and install it by following the instructions in Development Setup
- Follow the style convention in use (Google JavaScript style guide (ES2015+ version))
- Write code
- Write tests for your code
- Ensure all tests pass
- Ensure test coverage does not decrease
- Document your changes
- Send pull request
To setup this project for development do the following
- Fork the repository.
- Clone the repository locally using
git clone https://github.com/<your_fork>/netjsonconfig-editor.js.git
. - Enter the local project’s root folder
cd netjsonconfig-editor.js
- Install javascript dependencies. run
npm install
- You should be ready to go.
- Run
npm run dev
to start the development server to view any of the examples - Run
npm run build
to build the library andnpm run watch
to watch files for changes. - Run
npm run watch
to run a watch server to instantly build the javascript on change of any files.
- In order to run tests for the code written run the command
npm run test
writing tests is an essential part of the project. - Ensure to run a build before trying to run any tests. The tests will fail if you don't.
- All new features added to the editor need to be accompanied with appropriate tests, but also ensuring that tets written before do not fail.
- netjsonconfig-editor.js uses mocha js as the test framework, chaijs as the assertion library and phantomjs as the virtual DOM for command line tests To get started with
See CHANGELOG.
See LICENSE.