Skip to content

Commit 7caf98e

Browse files
committed
refactor: replace true/false text input with radio buttons
1 parent 3c894da commit 7caf98e

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

views/project.jade

+17-19
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ block content
1818
.col-sm-9
1919
input.form-control(type="number", value="#{val.default}", step="any", name="#{key}", id="#{key}", required)
2020
else if (val.type === "bool")
21-
// TODO Consider replacing with two radio buttons
2221
.form-group.row
2322
label.form-control-label.control-label.col-sm-3(for="#{key}") #{key}
2423
.col-sm-9
25-
input.form-control(type="text", value="#{val.default}", pattern="(true|false)", title="Enter true or false", name="#{key}", id="#{key}", required)
24+
.form-check.form-check-inline
25+
label.form-check-label
26+
input.form-check-input(type="radio", name="#{key}", id="#{key}-true", value="true", checked=val.default, required)
27+
span True
28+
.form-check.form-check-inline
29+
label.form-check-label
30+
input.form-check-input(type="radio", name="#{key}", id="#{key}-false", value="false", checked=!val.default, required)
31+
span False
2632
else if (val.type === "string")
2733
.form-group.row
2834
label.form-control-label.control-label.col-sm-3(for="#{key}") #{key}
@@ -86,28 +92,20 @@ block scripts
8692
}
8793
}
8894
}
89-
} else if ($el.attr("pattern")) {
90-
if (val !== "true" && val !== "false") {
91-
// Check bools
92-
$el.addClass("form-control-error");
93-
$formGroup.addClass("has-error");
94-
hasErrors = true;
95-
} else {
96-
// Convert bools
95+
} else if ($el.attr("type") === "radio") {
96+
// Convert bools
97+
if ($el.is(":checked")) {
9798
val = (val === "true");
9899
$el.addClass("form-control-success");
99100
$formGroup.addClass("has-success");
100-
}
101-
} else {
102-
if (val === "") {
103-
// Check strings
104-
$el.addClass("form-control-error");
105-
$formGroup.addClass("has-error");
106-
hasErrors = true;
107101
} else {
108-
$el.addClass("form-control-success");
109-
$formGroup.addClass("has-success");
102+
// Prevent "false" overwriting true
103+
val = (val === "false");
110104
}
105+
} else {
106+
// Do not check enums or strings (allow empty)
107+
$el.addClass("form-control-success");
108+
$formGroup.addClass("has-success");
111109
}
112110
formObj[name] = val; // Set key and value
113111
});

0 commit comments

Comments
 (0)