Skip to content

Commit

Permalink
03_04e Autofilling dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Villalobos committed Oct 1, 2016
1 parent fcd58e5 commit 156ad67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion data/data.json
@@ -1 +1 @@
[{"petName":"Buffy","ownerName":"Hassum Harrod","aptDate":"2016-06-20 15:30","aptNotes":"This Chihuahua has not eaten for three days and is lethargic"},{"petName":"Spot","ownerName":"Constance Smith","aptDate":"2016-06-24 08:30","aptNotes":"This German Shepherd is having some back pain"},{"petName":"Goldie","ownerName":"Barot Bellingham","aptDate":"2016-06-22 15:50","aptNotes":"This Goldfish has some weird spots in the belly"},{"petName":"Mitten","ownerName":"Hillary Goldwyn","aptDate":"2016-06-21 9:15","aptNotes":"Cat has excessive hairballs"}]
[{"petName":"Buffy","ownerName":"Hassum Harrod","aptDate":"2016-06-20 15:30","aptNotes":"This Chihuahua has not eaten for three days and is lethargic"},{"petName":"Spot","ownerName":"Constance Smith","aptDate":"2016-06-24 08:30","aptNotes":"This German Shepherd is having some back pain"},{"petName":"Goldie","ownerName":"Barot Bellingham","aptDate":"2016-06-22 15:50","aptNotes":"This Goldfish has some weird spots in the belly"},{"petName":"Mitten","ownerName":"Hillary Goldwyn","aptDate":"2016-06-21 9:15","aptNotes":"Cat has excessive hairballs"},{"petName":"Polly","ownerName":"Joe","aptDate":"2016-10-15 09:00","aptNotes":"Asks for too many crackers"}]
27 changes: 25 additions & 2 deletions process/js/AddAppointment.js
@@ -1,5 +1,20 @@
var React = require('react');

var defaultDate = new Date();
defaultDate.setDate(defaultDate.getDate() + 14);

function formatDate(date, divider) {
var someday = new Date(date);
var month = someday.getUTCMonth() + 1;
var day = someday.getUTCDate();
var year = someday.getUTCFullYear();

if (month <= 9) { month = '0' + month; }
if (day <= 9) { day = '0' + day; }

return ('' + year + divider + month + divider + day);
}

var AddAppointment = React.createClass({

toggleAptDisplay: function() {
Expand All @@ -16,6 +31,13 @@ var AddAppointment = React.createClass({
} //tempitems

this.props.addApt(tempItem);

this.inputPetName.value = '';
this.inputPetOwner.value = '';
this.inputAptDate.value = formatDate(defaultDate, '-');
this.inputAptTime.value = '09:00';
this.inputAptNotes.value = '';

}, //handleAdd

render: function() {
Expand Down Expand Up @@ -47,14 +69,15 @@ var AddAppointment = React.createClass({
<label className="col-sm-3 control-label" htmlFor="aptDate">Date</label>
<div className="col-sm-9">
<input type="date" className="form-control"
id="aptDate" ref={(ref) => this.inputAptDate = ref } />
id="aptDate" ref={(ref) => this.inputAptDate = ref }
defaultValue={formatDate(defaultDate, '-')} />
</div>
</div>
<div className="form-group">
<label className="col-sm-3 control-label" htmlFor="aptTime">Time</label>
<div className="col-sm-9">
<input type="time" className="form-control"
id="aptTime" ref={(ref) => this.inputAptTime = ref } />
id="aptTime" ref={(ref) => this.inputAptTime = ref } defaultValue={'09:00'} />
</div>
</div>
<div className="form-group">
Expand Down

0 comments on commit 156ad67

Please sign in to comment.