Working date changer!
This commit is contained in:
parent
95eb73a166
commit
72318bb286
2 changed files with 31 additions and 4 deletions
|
@ -1,13 +1,24 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var Curry = require("bs-platform/lib/js/curry.js");
|
||||||
var React = require("react");
|
var React = require("react");
|
||||||
var Moment = require("moment");
|
var Moment = require("moment");
|
||||||
|
|
||||||
function DatePicker(Props) {
|
function DatePicker(Props) {
|
||||||
var date = Moment().format("YYYY-MM-DD");
|
var match = React.useState((function () {
|
||||||
|
return Moment();
|
||||||
|
}));
|
||||||
|
var updateDate = match[1];
|
||||||
|
var handleChange = function ($$event) {
|
||||||
|
var value = $$event.target.value;
|
||||||
|
return Curry._1(updateDate, (function (param) {
|
||||||
|
return Moment(value, "YYYY-MM-DD");
|
||||||
|
}));
|
||||||
|
};
|
||||||
return React.createElement(React.Fragment, undefined, React.createElement("input", {
|
return React.createElement(React.Fragment, undefined, React.createElement("input", {
|
||||||
type: "date",
|
type: "date",
|
||||||
value: date
|
value: match[0].format("YYYY-MM-DD"),
|
||||||
|
onChange: handleChange
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
|
type formattedString = string;
|
||||||
|
|
||||||
[@react.component]
|
[@react.component]
|
||||||
let make = () => {
|
let make = () => {
|
||||||
let date = MomentRe.momentNow() |> MomentRe.Moment.format("YYYY-MM-DD");
|
let (date: MomentRe.Moment.t, updateDate) =
|
||||||
<> <input type_="date" value=date /> </>;
|
React.useState(MomentRe.momentNow);
|
||||||
|
|
||||||
|
let formatDate: MomentRe.Moment.t => formattedString =
|
||||||
|
(date: MomentRe.Moment.t) => {
|
||||||
|
date |> MomentRe.Moment.format("YYYY-MM-DD");
|
||||||
|
};
|
||||||
|
|
||||||
|
let handleChange = (event: ReactEvent.Form.t) => {
|
||||||
|
let value: formattedString = ReactEvent.Form.target(event)##value;
|
||||||
|
updateDate(_ => {value->MomentRe.momentWithFormat("YYYY-MM-DD")});
|
||||||
|
};
|
||||||
|
|
||||||
|
<>
|
||||||
|
<input type_="date" value={formatDate(date)} onChange=handleChange />
|
||||||
|
</>;
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue