Alexsandro Siregar
Alexsandro Siregar

Reputation: 65

How to Put date into input type date in react js

i have a problem with how to put date that i get from json data into date input, like i said i want to put it into input type date but the problem is when i console.log the date, its came out but its not cameout into field and still dd/mm/yyyy

mydate

{
  this.state.post2.map((h, i) => {
    if (
      `${h.username}` ===
      `${this.state.formData.username}`
    ) {
      return (
        <FormGroup>
          <FormGroup>
            <Label htmlFor="middleName">
              Middle Name
            </Label>
            <Input
              onChange={this.handleForm}
              key={i}
              defaultValue={h.middleName}
              type="text"
              name="middleName"
              className="form-control"
              placeholder="Middle Name"
              required=""
            />
          </FormGroup>
          <FormGroup>
            <Label htmlFor="lastName">Last Name</Label>
            <Input
              onChange={this.handleForm}
              key={i}
              defaultValue={h.lastName}
              type="text"
              name="lastName"
              className="form-control"
              placeholder="Last Name"
              required=""
            />
          </FormGroup>
          <FormGroup>
            <Label htmlFor="email">Email</Label>
            <Input
              onChange={this.handleForm}
              key={i}
              defaultValue={h.email}
              type="text"
              name="email"
              className="form-control"
              placeholder="Email"
              required=""
            />
          </FormGroup>
          <FormGroup>
            <Label htmlFor="phone">Phone Number</Label>
            <Input
              onChange={this.handleForm}
              value={h.phone}
              type="text"
              name="phone"
              className="form-control"
              placeholder="Phone Number"
              required=""
            />
          </FormGroup>
          <FormGroup>
            <Label for="expiredDate">
              Expired Date
            </Label>
            <Input
              type="date"
              name="expiredDate"
              onChange={this.handleForm}
              defaultValue={new Date(h.expiredDate)}
              placeholder="date placeholder"
              min={moment().format('YYYY-MM-DD')}
            />
          </FormGroup>
        </FormGroup>
      );
    }
  });
}

response in console.log

25-01-2021 07:00:00

i already try to console.log and it appear but not appear on field and still dd/mm/yyyy how to change dd/mm/yyyy into date that i get ?

Upvotes: 0

Views: 6719

Answers (1)

Sukrut Bam
Sukrut Bam

Reputation: 87

What about this defaultValue={moment(new Date(h.expiredDate)).format('YYYY-MM-DD')} not sure about moment parameters.Need to check.

Upvotes: 2

Related Questions