Permalink
Browse files

Add a utility function to extract values from input events

  • Loading branch information...
markerikson committed Jan 2, 2017
1 parent 2cca3ea commit 745eda848672679bee971d2783cd6e4102648d0e
Showing with 21 additions and 3 deletions.
  1. +19 −0 src/common/utils/clientUtils.js
  2. +2 −3 src/features/unitInfo/UnitInfo/UnitInfo.jsx
@@ -0,0 +1,19 @@
import {isObject} from "lodash";
export function getValueFromEvent(e) {
const {target} = e;
let newValues;
if(target) {
const value = (target.type === "checkbox") ? target.checked : target.value;
newValues = {
[target.name] : value,
};
}
else if(isObject(e)) {
newValues = e;
}
return newValues;
}
@@ -8,6 +8,7 @@ import {
import {selectUnitInfo} from "../unitInfoSelectors";
import {updateUnitInfo} from "../unitInfoActions";
import {getValueFromEvent} from "common/utils/clientUtils";
const FACTIONS = [
{value : "cc", text : "Capellan Confederation"},
@@ -38,9 +39,7 @@ class UnitInfo extends Component {
}
onNameChanged = (e) => {
const {name, value} = e.target;
const newValues = { [name] : value};
const newValues = getValueFromEvent(e);
this.props.updateUnitInfo(newValues);
}

0 comments on commit 745eda8

Please sign in to comment.