Skip to content

Commit 740ed44

Browse files
committed
form field options
1 parent fd4427c commit 740ed44

File tree

6 files changed

+1183
-6
lines changed

6 files changed

+1183
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { BaseOptionComponent, useDomState } from "@html_builder/core/utils";
2+
import { onWillStart, onWillUpdateProps, useState } from "@odoo/owl";
3+
import { FormActionFieldsOption } from "./form_action_fields_option";
4+
import { getDependencyEl, getMultipleInputs, isFieldCustom } from "./utils";
5+
6+
export class FormFieldOption extends BaseOptionComponent {
7+
static template = "html_builder.website.s_website_form_field_option";
8+
static props = {
9+
loadFieldOptionData: Function,
10+
redrawSequence: { type: Number, optional: true },
11+
};
12+
static components = { FormActionFieldsOption };
13+
14+
setup() {
15+
super.setup();
16+
this.state = useState({
17+
availableFields: [],
18+
conditionInputs: [],
19+
conditionValueList: [],
20+
dependencyEl: null,
21+
});
22+
this.domState = useDomState((el) => ({ el }));
23+
onWillStart(async () => {
24+
const el = this.env.getEditingElement();
25+
const fieldOptionData = await this.props.loadFieldOptionData(el);
26+
this.state.availableFields.push(...fieldOptionData.availableFields);
27+
this.state.conditionInputs.push(...fieldOptionData.conditionInputs);
28+
this.state.conditionValueList.push(...fieldOptionData.conditionValueList);
29+
this.state.dependencyEl = getDependencyEl(el);
30+
});
31+
onWillUpdateProps(async (props) => {
32+
const el = this.env.getEditingElement();
33+
const fieldOptionData = await props.loadFieldOptionData(el);
34+
this.state.availableFields.length = 0;
35+
this.state.availableFields.push(...fieldOptionData.availableFields);
36+
this.state.conditionInputs.length = 0;
37+
this.state.conditionInputs.push(...fieldOptionData.conditionInputs);
38+
this.state.conditionValueList.length = 0;
39+
this.state.conditionValueList.push(...fieldOptionData.conditionValueList);
40+
this.state.dependencyEl = getDependencyEl(el);
41+
});
42+
// TODO select field's hack ?
43+
}
44+
get isTextConditionValueVisible() {
45+
const el = this.env.getEditingElement();
46+
const dependencyEl = getDependencyEl(el);
47+
if (
48+
!el.classList.contains("s_website_form_field_hidden_if") ||
49+
(dependencyEl &&
50+
(["checkbox", "radio"].includes(dependencyEl.type) ||
51+
dependencyEl.nodeName === "SELECT"))
52+
) {
53+
return false;
54+
}
55+
if (!dependencyEl) {
56+
return true;
57+
}
58+
if (dependencyEl?.classList.contains("datetimepicker-input")) {
59+
return false;
60+
}
61+
return (
62+
(["text", "email", "tel", "url", "search", "password", "number"].includes(
63+
dependencyEl.type
64+
) ||
65+
dependencyEl.nodeName === "TEXTAREA") &&
66+
!["set", "!set"].includes(el.dataset.visibilityComparator)
67+
);
68+
}
69+
get isTextConditionOperatorVisible() {
70+
const el = this.env.getEditingElement();
71+
const dependencyEl = getDependencyEl(el);
72+
if (
73+
!el.classList.contains("s_website_form_field_hidden_if") ||
74+
dependencyEl?.classList.contains("datetimepicker-input")
75+
) {
76+
return false;
77+
}
78+
return (
79+
!dependencyEl ||
80+
["text", "email", "tel", "url", "search", "password"].includes(dependencyEl.type) ||
81+
dependencyEl.nodeName === "TEXTAREA"
82+
);
83+
}
84+
get isExisingFieldSelectType() {
85+
const el = this.env.getEditingElement();
86+
return !isFieldCustom(el) && ["selection", "many2one"].includes(el.dataset.type);
87+
}
88+
get isMultipleInputs() {
89+
const el = this.env.getEditingElement();
90+
return !!getMultipleInputs(el);
91+
}
92+
get isMaxFilesVisible() {
93+
// Do not display the option if only one file is supposed to be
94+
// uploaded in the field.
95+
const el = this.env.getEditingElement();
96+
const fieldEl = el.closest(".s_website_form_field");
97+
return (
98+
fieldEl.classList.contains("s_website_form_custom") ||
99+
["one2many", "many2many"].includes(fieldEl.dataset.type)
100+
);
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { BaseOptionComponent, useDomState } from "@html_builder/core/utils";
2+
import { FormFieldOption } from "./form_field_option";
3+
4+
export class FormFieldOptionRedraw extends BaseOptionComponent {
5+
static template = "html_builder.website.s_website_form_field_option_redraw";
6+
static props = FormFieldOption.props;
7+
static components = { FormFieldOption };
8+
9+
setup() {
10+
super.setup();
11+
this.count = 0;
12+
this.domState = useDomState((el) => {
13+
this.count++;
14+
return {
15+
redrawSequence: this.count++,
16+
};
17+
});
18+
}
19+
}

Diff for: addons/html_builder/static/src/website_builder/plugins/form/form_option.inside.scss

+17-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
}
88
}
99

10-
.s_website_form input:not(.o_translatable_attribute) {
11-
pointer-events: none;
12-
}
10+
.s_website_form {
11+
input, textarea, select, .s_website_form_label {
12+
&:not(.o_translatable_attribute) {
13+
pointer-events: none;
14+
}
15+
}
16+
// Hidden field is only partially hidden in editor
17+
.s_website_form_field_hidden {
18+
display: block !important;
19+
opacity: 0.5;
20+
}
21+
// Fields with conditional visibility are visible and identifiable in the editor
22+
.s_website_form_field_hidden_if {
23+
display: block !important;
24+
background-color: $o-we-fg-light;
25+
}
26+
}

0 commit comments

Comments
 (0)