Skip to content

Commit 0c27daf

Browse files
committed
adding custom UI for boolean field
1 parent 65f5da7 commit 0c27daf

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

packages/tdb-documents-ui/src/dataTypeFrames/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export function getFormat(frame, item) {
126126
*/
127127
return widget.getTextareaUIWidget(CONST.XSD_STRING, mode, data)
128128
}
129+
if(frame[item] === CONST.XSD_BOOLEAN) return widget.getBooleanUI(mode, data)
129130
/** Commenting out HTML support as of now */
130131
/*else if (frame[item] === CONST.XDD_HTML) {
131132
return { ["ui:field"]: widget.getEditHTMLUI }

packages/tdb-documents-ui/src/dataTypeFrames/widget.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ import * as util from "../utils"
1212
import MDEditor, { commands } from '@uiw/react-md-editor';
1313
import mermaid from "mermaid";
1414
import uuid from 'react-uuid'
15+
import InputGroup from 'react-bootstrap/InputGroup';
16+
17+
function booleanField(mode, props) {
18+
const [checked, setChecked] = useState(mode !== CONST.CREATE ? props.formData : false)
19+
20+
function handleClick() {
21+
setChecked(!checked)
22+
props.onChange(!checked)
23+
}
24+
return <InputGroup className="mb-3 w-100">
25+
{mode !== CONST.VIEW && <div className={`control-label`}>
26+
{props.name}
27+
{props.required && <span className="required">{"*"}</span>}
28+
</div>}
29+
<Stack direction={"horizontal"} gap={2}>
30+
{checked && <input type="checkbox" id={props.name} name={props.name} checked onChange={handleClick}/>}
31+
{!checked && <input type="checkbox" id={props.name} name={props.name} onChange={handleClick}/>}
32+
<span>{props.name}</span>
33+
</Stack>
34+
</InputGroup>
35+
}
36+
37+
export function getBooleanUI (mode, data) {
38+
let uiLayout = {}
39+
function displayBooleanField(props) {
40+
return booleanField(mode, props)
41+
}
42+
uiLayout["ui:field"] = displayBooleanField
43+
return uiLayout
44+
}
1545

1646
// function to provide a ui widget to textarea for xsd:string types
1747
export function getTextareaUIWidget(placeholder, mode, data) {

packages/tdb-documents-ui/src/helpers/formDataHelper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export function getFormData(frame, item, mode, formData) {
77
if(!frame.hasOwnProperty(item)) return null
88

99
if(util.isDataType(frame[item])) {
10+
if(frame[item] === CONST.XSD_BOOLEAN) return false
1011
return util.getDefaultValue(item, formData)
1112
}
1213

packages/tdb-documents-ui/src/mandatoryFrames.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export function makeMandatoryFrames (fullFrame, item, frame, uiFrame, mode, form
7575
let data=dataProvider.getFormData(frame, item, mode, formData)
7676
if(data) layout["default"]=data
7777
}
78+
if(layout["type"] === CONST.BOOLEAN_TYPE) {
79+
let data=dataProvider.getFormData(frame, item, mode, formData)
80+
if(!data) layout["default"]=data
81+
}
7882

7983
/** gather ui layout of property to change look and feel */
8084
let uiLayout = generateUI(fullFrame, frame, item, uiFrame, mode, formData, onTraverse, onSelect, documentation, extractedFrames, docType)

0 commit comments

Comments
 (0)