Skip to content

Commit

Permalink
Set terminus to undefined in period form if it doesn't have any values
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
ptgolden committed Nov 15, 2015
1 parent 1f0f624 commit 516d1e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/period_form/terminus_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,28 @@ module.exports = React.createClass({
},

handleChangeAutoparsedLabel: function (e) {
var terminus = parse(e.target.value);
this.props.onChange(terminus);
},
var label = e.target.value;
this.props.onChange(label.length ? parse(label) : undefined);
},

refreshAutoparse: function () {
var terminus = parse(this.props.terminus.get('label'));
this.props.onChange(terminus);
},

handleChange: function (field, e) {
var value = e.target.value;
this.props.onChange(this.props.terminus.setIn([].concat(field), value));
var { hasISOValue } = require('../../helpers/terminus')
, { terminus, onChange } = this.props
, value = e.target.value
, updatedTerminus = terminus.setIn([].concat(field), value)
, isEmpty

isEmpty = (
updatedTerminus.get('label').length === 0 &&
!hasISOValue(updatedTerminus)
)

onChange(isEmpty ? undefined : updatedTerminus);
},

render: function () {
Expand Down
15 changes: 15 additions & 0 deletions src/tests/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ describe('Period form', function () {
});
});

it('Should have a null value for empty period termini', function () {
var view = makePeriodFormView()
, { startTerminus, stopTerminus } = view.refs.temporalCoverage.refs

Simulate.change(
React.findDOMNode(startTerminus).querySelector('[name="label"]'),
{ target: { value: '1890'}});

Simulate.change(
React.findDOMNode(startTerminus).querySelector('[name="label"]'),
{ target: { value: ''}});

assert.equal(view.getPeriodValue().get('start'), null);
});

/*
it('Should render errors', function () {
var view = makePeriodFormView();
Expand Down

0 comments on commit 516d1e3

Please sign in to comment.