diff --git a/jsonform.js.md b/jsonform.js.md index a4eb295..855665a 100644 --- a/jsonform.js.md +++ b/jsonform.js.md @@ -8,21 +8,70 @@ import { JsonForm, TextField, NumberField } from './jsonform.js'; ### property editable +This is a boolean property that determines whether the form can be edited. If `editable` is false, the form is view-only; if `editable` is true, the form becomes editable. + +```javascript +myForm.editable = true; // make form editable +myForm.editable = false; // make form view-only and update the model +``` + ### property model +This property holds the data model used to populate the form. It should in most cases be an object. + +```javascript +let record = { id: 42, type: "note", description: "This is a note." }; +myForm.model = record; +``` + ### property layout +Access the `FormLayout` of the form. + +### dom() → Element + +Get the DOM of the form. This can be passed to a new dialog as the body, or appended to an element on the webpage. + +```javascript +const formContainer = document.querySelector('#formcontainer'); +formContainer.appendChild(myForm.dom()); +``` + ## class FormLayout This class can not be created, only accessed via `JsonForm.layout`. +### addRow() → FormRow + +```javascript +let newRow = myForm.layout.addRow(); +``` + ## class FormRow This class can not be created directly, only via `FormLayout.addRow()`. +### append(field) → self + +```javascript +let newRow = myForm.layout.addRow(); +newRow.append(new TextField({ label:"Description", path:".description" })); +``` + ## class Field +Common field options: + +- **label** - string: the field label +- **path** - string: the JSON path in the model for this field +- **locked** - bool: make field read-only +- **nullable** - bool: assume null for this value if the field is empty + ## class TextField ## class NumberField +- **fixed** - int: save the number as a string, with *n* decimals. +- **float** - bool: save the number as a float, unrounded. + +Note: If neither **fixed** or **float** is set, the value will be saved as an integer. \ No newline at end of file