aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/fields/InputField.js
diff options
context:
space:
mode:
authorEmiliano Ciavatta2020-09-29 16:56:00 +0000
committerEmiliano Ciavatta2020-09-29 16:56:00 +0000
commitd994a21a0dfae9ee026e8aa3ccdee6c213c523aa (patch)
treea9d343300d3b9587bdaa664ef9f005ddc9529656 /frontend/src/components/fields/InputField.js
parent7f4cc5d3f3f92338a464853c182b9d6a3ea850eb (diff)
Complete rules page
Diffstat (limited to 'frontend/src/components/fields/InputField.js')
-rw-r--r--frontend/src/components/fields/InputField.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/frontend/src/components/fields/InputField.js b/frontend/src/components/fields/InputField.js
index 6cf967a..b790891 100644
--- a/frontend/src/components/fields/InputField.js
+++ b/frontend/src/components/fields/InputField.js
@@ -20,16 +20,17 @@ class InputField extends Component {
const inline = this.props.inline || false;
const name = this.props.name || null;
const value = this.props.value || "";
+ const defaultValue = this.props.defaultValue || "";
const type = this.props.type || "text";
const error = this.props.error || null;
- const defaultValue = this.props.defaultValue || null;
+
const handler = (e) => {
- if (this.props.onChange) {
+ if (typeof this.props.onChange === "function") {
if (type === "file") {
let file = e.target.files[0];
this.props.onChange(file);
} else if (e == null) {
- this.props.onChange("");
+ this.props.onChange(defaultValue);
} else {
this.props.onChange(e.target.value);
}
@@ -37,7 +38,7 @@ class InputField extends Component {
};
let inputProps = {};
if (type !== "file") {
- inputProps["value"] = value || this.props.initialValue;
+ inputProps["value"] = value || defaultValue;
}
return (
@@ -52,8 +53,8 @@ class InputField extends Component {
<div className="field-input">
<div className="field-value">
{ type === "file" && <label for={this.id} className={"file-label"}>
- {value.name || defaultValue}</label> }
- <input type={type} placeholder={defaultValue} id={this.id}
+ {value.name || this.props.placeholder}</label> }
+ <input type={type} placeholder={this.props.placeholder} id={this.id}
aria-describedby={this.id} onChange={handler} {...inputProps} />
</div>
{ type !== "file" && value !== "" &&