mirror of
https://github.com/ascribe/onion.git
synced 2024-11-13 16:45:05 +01:00
add defaultValue to inputdate
This commit is contained in:
parent
d5dc164810
commit
1620437c86
@ -25,8 +25,8 @@ let LoanForm = React.createClass({
|
||||
fullform: React.PropTypes.bool,
|
||||
email: React.PropTypes.string,
|
||||
gallery: React.PropTypes.string,
|
||||
startdate: React.PropTypes.string,
|
||||
enddate: React.PropTypes.string,
|
||||
startdate: React.PropTypes.object,
|
||||
enddate: React.PropTypes.object,
|
||||
showPersonalMessage: React.PropTypes.bool,
|
||||
|
||||
url: React.PropTypes.string,
|
||||
@ -167,7 +167,7 @@ let LoanForm = React.createClass({
|
||||
label={getLangText('Start date')}
|
||||
hidden={!this.props.startdate}>
|
||||
<InputDate
|
||||
value={this.props.startdate}
|
||||
defaultValue={this.props.startdate}
|
||||
placeholderText={getLangText('Loan start date')} />
|
||||
</Property>
|
||||
<Property
|
||||
@ -175,7 +175,7 @@ let LoanForm = React.createClass({
|
||||
label={getLangText('End date')}
|
||||
hidden={!this.props.enddate}>
|
||||
<InputDate
|
||||
value={this.props.enddate}
|
||||
defaultValue={this.props.enddate}
|
||||
placeholderText={getLangText('Loan end date')} />
|
||||
</Property>
|
||||
<Property
|
||||
|
@ -8,7 +8,8 @@ let InputDate = React.createClass({
|
||||
propTypes: {
|
||||
submitted: React.PropTypes.bool,
|
||||
placeholderText: React.PropTypes.string,
|
||||
onChange: React.PropTypes.func
|
||||
onChange: React.PropTypes.func,
|
||||
defaultValue: React.PropTypes.object
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
@ -17,6 +18,12 @@ let InputDate = React.createClass({
|
||||
};
|
||||
},
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if(!this.state.value && !this.state.value_moment && nextProps.defaultValue) {
|
||||
this.handleChange(this.props.defaultValue);
|
||||
}
|
||||
},
|
||||
|
||||
handleChange(date) {
|
||||
let formattedDate = date.format('YYYY-MM-DD');
|
||||
this.setState({
|
||||
|
@ -3,6 +3,8 @@
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
|
||||
import Moment from 'moment';
|
||||
|
||||
import Col from 'react-bootstrap/lib/Col';
|
||||
import Row from 'react-bootstrap/lib/Row';
|
||||
|
||||
@ -32,7 +34,7 @@ import SlidesContainer from '../../../../ascribe_slides_container/slides_contain
|
||||
import ApiUrls from '../../../../../constants/api_urls';
|
||||
|
||||
import { getLangText } from '../../../../../utils/lang_utils';
|
||||
import { mergeOptions, dateToString } from '../../../../../utils/general_utils';
|
||||
import { mergeOptions } from '../../../../../utils/general_utils';
|
||||
import { getAclFormMessage } from '../../../../../utils/form_utils';
|
||||
|
||||
let CylandRegisterPiece = React.createClass({
|
||||
@ -115,9 +117,9 @@ let CylandRegisterPiece = React.createClass({
|
||||
|
||||
render() {
|
||||
|
||||
let today = new Date();
|
||||
let datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain = new Date();
|
||||
datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain.setFullYear(3000);
|
||||
let today = new Moment();
|
||||
let datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain = new Moment();
|
||||
datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain.add(1000, 'years');
|
||||
|
||||
return (
|
||||
<SlidesContainer ref="slidesContainer">
|
||||
@ -167,8 +169,8 @@ let CylandRegisterPiece = React.createClass({
|
||||
url={ApiUrls.ownership_loans_pieces}
|
||||
email="videoarchive@cyland.org"
|
||||
gallery="Cyland Archive"
|
||||
startdate={dateToString(today)}
|
||||
enddate={dateToString(datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain)}/>
|
||||
startdate={today}
|
||||
enddate={datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain}/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
@ -177,26 +177,4 @@ function _mergeOptions(obj1, obj2) {
|
||||
*/
|
||||
export function escapeHTML(s) {
|
||||
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date object to a string.
|
||||
* Taken from: http://stackoverflow.com/a/4929629/1263876
|
||||
* @param {date} date a javascript date
|
||||
* @return {string} a string, in format: DD-MM-YYY
|
||||
*/
|
||||
export function dateToString(date) {
|
||||
var dd = date.getDate();
|
||||
var mm = date.getMonth() + 1; //January is 0!
|
||||
var yyyy = date.getFullYear();
|
||||
|
||||
if(dd < 10) {
|
||||
dd = '0' + dd;
|
||||
}
|
||||
|
||||
if(mm < 10) {
|
||||
mm = '0' + mm;
|
||||
}
|
||||
|
||||
return dd + '-' + mm + '-' + yyyy;
|
||||
}
|
@ -67,6 +67,7 @@
|
||||
"isomorphic-fetch": "^2.0.2",
|
||||
"jest-cli": "^0.4.0",
|
||||
"lodash": "^3.9.3",
|
||||
"moment": "^2.10.6",
|
||||
"object-assign": "^2.0.0",
|
||||
"q": "^1.4.1",
|
||||
"raven-js": "^1.1.19",
|
||||
|
Loading…
Reference in New Issue
Block a user