mirror of
https://github.com/ascribe/onion.git
synced 2025-01-05 11:25:09 +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,
|
fullform: React.PropTypes.bool,
|
||||||
email: React.PropTypes.string,
|
email: React.PropTypes.string,
|
||||||
gallery: React.PropTypes.string,
|
gallery: React.PropTypes.string,
|
||||||
startdate: React.PropTypes.string,
|
startdate: React.PropTypes.object,
|
||||||
enddate: React.PropTypes.string,
|
enddate: React.PropTypes.object,
|
||||||
showPersonalMessage: React.PropTypes.bool,
|
showPersonalMessage: React.PropTypes.bool,
|
||||||
|
|
||||||
url: React.PropTypes.string,
|
url: React.PropTypes.string,
|
||||||
@ -167,7 +167,7 @@ let LoanForm = React.createClass({
|
|||||||
label={getLangText('Start date')}
|
label={getLangText('Start date')}
|
||||||
hidden={!this.props.startdate}>
|
hidden={!this.props.startdate}>
|
||||||
<InputDate
|
<InputDate
|
||||||
value={this.props.startdate}
|
defaultValue={this.props.startdate}
|
||||||
placeholderText={getLangText('Loan start date')} />
|
placeholderText={getLangText('Loan start date')} />
|
||||||
</Property>
|
</Property>
|
||||||
<Property
|
<Property
|
||||||
@ -175,7 +175,7 @@ let LoanForm = React.createClass({
|
|||||||
label={getLangText('End date')}
|
label={getLangText('End date')}
|
||||||
hidden={!this.props.enddate}>
|
hidden={!this.props.enddate}>
|
||||||
<InputDate
|
<InputDate
|
||||||
value={this.props.enddate}
|
defaultValue={this.props.enddate}
|
||||||
placeholderText={getLangText('Loan end date')} />
|
placeholderText={getLangText('Loan end date')} />
|
||||||
</Property>
|
</Property>
|
||||||
<Property
|
<Property
|
||||||
|
@ -8,7 +8,8 @@ let InputDate = React.createClass({
|
|||||||
propTypes: {
|
propTypes: {
|
||||||
submitted: React.PropTypes.bool,
|
submitted: React.PropTypes.bool,
|
||||||
placeholderText: React.PropTypes.string,
|
placeholderText: React.PropTypes.string,
|
||||||
onChange: React.PropTypes.func
|
onChange: React.PropTypes.func,
|
||||||
|
defaultValue: React.PropTypes.object
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
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) {
|
handleChange(date) {
|
||||||
let formattedDate = date.format('YYYY-MM-DD');
|
let formattedDate = date.format('YYYY-MM-DD');
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Router from 'react-router';
|
import Router from 'react-router';
|
||||||
|
|
||||||
|
import Moment from 'moment';
|
||||||
|
|
||||||
import Col from 'react-bootstrap/lib/Col';
|
import Col from 'react-bootstrap/lib/Col';
|
||||||
import Row from 'react-bootstrap/lib/Row';
|
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 ApiUrls from '../../../../../constants/api_urls';
|
||||||
|
|
||||||
import { getLangText } from '../../../../../utils/lang_utils';
|
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';
|
import { getAclFormMessage } from '../../../../../utils/form_utils';
|
||||||
|
|
||||||
let CylandRegisterPiece = React.createClass({
|
let CylandRegisterPiece = React.createClass({
|
||||||
@ -115,9 +117,9 @@ let CylandRegisterPiece = React.createClass({
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
let today = new Date();
|
let today = new Moment();
|
||||||
let datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain = new Date();
|
let datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain = new Moment();
|
||||||
datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain.setFullYear(3000);
|
datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain.add(1000, 'years');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SlidesContainer ref="slidesContainer">
|
<SlidesContainer ref="slidesContainer">
|
||||||
@ -167,8 +169,8 @@ let CylandRegisterPiece = React.createClass({
|
|||||||
url={ApiUrls.ownership_loans_pieces}
|
url={ApiUrls.ownership_loans_pieces}
|
||||||
email="videoarchive@cyland.org"
|
email="videoarchive@cyland.org"
|
||||||
gallery="Cyland Archive"
|
gallery="Cyland Archive"
|
||||||
startdate={dateToString(today)}
|
startdate={today}
|
||||||
enddate={dateToString(datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain)}/>
|
enddate={datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain}/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
@ -178,25 +178,3 @@ function _mergeOptions(obj1, obj2) {
|
|||||||
export function escapeHTML(s) {
|
export function escapeHTML(s) {
|
||||||
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
|
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",
|
"isomorphic-fetch": "^2.0.2",
|
||||||
"jest-cli": "^0.4.0",
|
"jest-cli": "^0.4.0",
|
||||||
"lodash": "^3.9.3",
|
"lodash": "^3.9.3",
|
||||||
|
"moment": "^2.10.6",
|
||||||
"object-assign": "^2.0.0",
|
"object-assign": "^2.0.0",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"raven-js": "^1.1.19",
|
"raven-js": "^1.1.19",
|
||||||
|
Loading…
Reference in New Issue
Block a user