Skip to content

Commit c7182a5

Browse files
committed
2321: Added checkbox options component for use in calendar modifiers
1 parent ef3032c commit c7182a5

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ All notable changes to this project will be documented in this file.
55

66
## [Unreleased]
77

8+
- [#264](https://github.com/os2display/display-admin-client/pull/264)
9+
- Added checkbox options component for use in calendar modifiers.
810
- [#260](https://github.com/os2display/display-admin-client/pull/260)
9-
- Bug in multiselect, fixed by removing duplicates by key both `@id`and `id`
10-
11+
- Bug in multiselect, fixed by removing duplicates by key both `@id`and `id`
1112
- [#259](https://github.com/os2display/display-admin-client/pull/259)
1213
- Add saving of playlists/groups with screen (as opposed to _after_)
1314
- Clean up `screen-manager.jsx`

src/components/slide/content/content-form.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import FormTable from "../../util/forms/form-table/form-table";
99
import FileSelector from "./file-selector";
1010
import StationSelector from "./station/station-selector";
1111
import RadioButtons from "../../util/forms/radio-buttons";
12+
import CheckboxOptions from "../../util/forms/checkbox-options.jsx";
1213

1314
/**
1415
* Render form elements for content form.
@@ -52,6 +53,9 @@ function ContentForm({
5253
let returnElement;
5354
let defaultMimetypes = null;
5455
switch (formData.input) {
56+
case "checkbox-options":
57+
returnElement = <CheckboxOptions formData={formData} data={formStateObject} onChange={onChange} />;
58+
break;
5559
case "image":
5660
case "video":
5761
case "file":
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { React } from "react";
2+
3+
function CheckboxOptions({formData, data, onChange}) {
4+
const values = data[formData.name];
5+
6+
const containsValue = (value) => {
7+
return values.includes(value);
8+
}
9+
10+
const onOptionChange = ({target}) => {
11+
const value = target.value;
12+
13+
const newValues = [...values];
14+
15+
if (newValues.includes(value)) {
16+
newValues.splice(newValues.indexOf(value), 1);
17+
} else {
18+
newValues.push(value);
19+
}
20+
21+
onChange({
22+
target: { id: formData.name, value: newValues },
23+
});
24+
}
25+
26+
return (<>
27+
{
28+
formData.options.map(option =>
29+
<div className={formData.formGroupClasses}>
30+
<input type="checkbox" key={option.value} value={option.value} onChange={onOptionChange} checked={containsValue(option.value)} /> {option.title}
31+
</div>
32+
)
33+
}
34+
</>);
35+
}
36+
37+
export default CheckboxOptions;

0 commit comments

Comments
 (0)