Skip to content

Commit

Permalink
Merge pull request #10 from black-trooper/feature/su-datepicker
Browse files Browse the repository at this point in the history
Fix the problem where value of input field is not update when value is changed
  • Loading branch information
black-trooper committed Dec 10, 2018
2 parents c6c85ff + 8e05a55 commit 66142bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dist/tags/datepicker/su-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ riot.tag2('su-datepicker', '<div class="ui {dropdown:opts.popup}"> <div class="u
changed = true
}
setValueFromValueAsDate()
if (changed && this.refs.input) {
this.refs.input.value = this.value
}

if (changed && this.valueAsDate) {
this.currentDate = copyDate(this.valueAsDate)
Expand Down
3 changes: 3 additions & 0 deletions tags/datepicker/su-datepicker.tag
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@
changed = true
}
setValueFromValueAsDate()
if (changed && this.refs.input) {
this.refs.input.value = this.value
}

if (changed && this.valueAsDate) {
this.currentDate = copyDate(this.valueAsDate)
Expand Down
7 changes: 7 additions & 0 deletions test/spec/datepicker/su-datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ describe('su-datepicker', function () {
spyOnClose.should.have.been.calledOnce
$('su-datepicker .menu').is(':visible').should.equal(false)
tag.refs.input.value.should.equal('2017-12-01')

tag.value = new Date(2018, 11, 1)
tag.update()
tag.refs.input.value.should.equal('2018-12-01')
})

it('popup datepicker option', function () {
Expand Down Expand Up @@ -411,6 +415,7 @@ describe('su-datepicker', function () {

tag.valueAsDate.getTime().should.equal(date.getTime())
tag.defaultValue.getTime().should.equal(date.getTime())
tag.changed().should.equal(false)

fireEvent($('su-datepicker .dp-today .button')[0], 'click')
const today = new Date()
Expand All @@ -419,9 +424,11 @@ describe('su-datepicker', function () {
tag.valueAsDate.getMonth().should.equal(today.getMonth())
tag.valueAsDate.getDate().should.equal(today.getDate())
tag.defaultValue.getTime().should.equal(date.getTime())
tag.changed().should.equal(true)

tag.reset()
tag.valueAsDate.getTime().should.equal(date.getTime())
tag.defaultValue.getTime().should.equal(date.getTime())
tag.changed().should.equal(false)
})
})

0 comments on commit 66142bd

Please sign in to comment.