html form json,GitHub - jsonform/jsonform: Build forms from JSON Schema. Easily template-able. Compa...

JSON Form

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e7376673f6c6f6e6743616368653d74727565

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f6c6f6e6743616368653d74727565

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d61696e7461696e65642d7965732d627269676874677265656e2e7376673f6c6f6e6743616368653d74727565

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a736f6e666f726d2f6a736f6e666f726d2e737667

68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f6a736f6e666f726d2e737667

The JSON Form library is a JavaScript client-side library that takes a

structured data model defined using JSON Schema as

input and returns a Bootstrap 3-friendly

HTML form that matches the schema.

The generated HTML form includes client-side validation logic that provides direct inline feedback to the user upon form submission (provided a JSON Schema validator is available). If values are valid, the JSON Form library uses submitted values to create the JavaScript data structure that matches the data model.

The layout of the generated HTML form may be entirely fine-tuned through

a simple declarative mechanism.

Getting started

The example below creates a form that asks for the user's name and age. The user's name is a required field, while the age is optional.

Getting started with JSON Form

Getting started with JSON Form

$('form').jsonForm({

schema: {

name: {

type: 'string',

title: 'Name',

required: true

},

age: {

type: 'number',

title: 'Age'

}

},

onSubmit: function (errors, values) {

if (errors) {

$('#res').html('

I beg your pardon?

');

}

else {

$('#res').html('

Hello ' + values.name + '.' +

(values.age ? '
You are ' + values.age + '.' : '') +

'

');

}

}

});

Loading this page in a browser renders a form with two input fields and a submit button. The onSubmit function is called upon form submission. If you press "Submit" without entering values or if the age you enter is not a number, error messages appear next to the input fields.

NB: Paths in this example are relative to the root of the JSON Form project.

Documentation

You can do much more with the JSON Form library. You may define a more complex data model that includes arrays and objects for instance, or you may control the layout of the form to include fieldsets, expandable sections or tabs. For more information, check the reference documentation for JSON Form.

Playground

If you're more of the acting type than of the reading type, the JSON Form Playground is a simple JSON Form editor that lets you try out and extend all the examples in the doc.

Dependencies

At a minimum, the JSON Form library depends on:

The JSON Form library may require further libraries, depending on the features you need for the forms you need to render. In particular:

ACE is needed to render rich text input fields. The deps/opt/ace folder contains a minimal set of files from ACE to render a JSON input field. Beware that the code of ace.js needs to be encapsulated in (function(require,define,requirejs) {...})(undefined,undefined,undefined); before it may be used within JSON Form.

Bootstrap v3.3 or above is more or less needed (unless you enjoy ugly forms, that is) if you don't provide your own styles. JSON Form only needs the bootstrap.css file.

The JSON Schema Validator is used to detect and report validation errors upon form submission. The deps/opt folder contains a "build" of the JSON Schema Validator for use in JSON Form.

Bootstrap Dropdowns v2.0.3 or above is needed for imageselect fields.

jQuery UI Sortable v1.8.20 or above is required for drag-and-drop support within arrays and tabarrays. Note the plugin itself depends on jQuery IU Core, jQuery UI Mouse, and jQuery UI Widget.

wysihtml5 is required if the form uses wysihtml5 textarea fields.

Spectrum is required if the form uses color fields.

All of these libraries are in the deps folder for now, although you might want to check their respective Web site for more recent versions.

NB: JSON Form also uses JSON.parse and JSON.stringify which is normally already natively supported by all modern browsers.

License

The JSON Form library is licensed under the MIT license.

All the libraries that JSON Form may depend on are licensed under the MIT license, except for the JSON Schema Validator, licensed under the BSD 3 Clause license and the ACE editor licensed under the Mozilla tri-license (MPL/GPL/LGPL).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值