0

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 ?

11
  • Can you show us what the Input component is? Commented Oct 11, 2019 at 10:40
  • any change on - new Date(h.expiredDate).toString() ? Commented Oct 11, 2019 at 10:41
  • the input commpoent in the UI is dd/mm/yyyy and can select the date. Commented Oct 11, 2019 at 10:41
  • no change toString. still dd/mm/yyyy Commented Oct 11, 2019 at 10:42
  • No, I would like to see the code for Input, where does it come from? If you want to respond to someone you should use @name Commented Oct 11, 2019 at 10:43

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

7 Comments

still dd/mm/yyyy in field. btw i use argon template
That is the correct way of setting value of input (lower case). But OP uses Input (upper case) and has difficulty telling us where Input comes from. Also OP sets defaultValue and that doesn't do anything with input (lower case) no matter if the format is correct or not.
@HMR it comes from reactstrap and if i use <input still dd/mm/yyy ,
@AlexsandroSiregar maybe read my comment first before replying' input (lower case) does not have a property called defaultValue.
i already change ma bro. why i use defaultValue ? to edit the field. if i use value, the field cannt be edit. thats why i use defaultValue
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.